Skip to content

Commit 277a0ed

Browse files
committed
change the max square for grains
1 parent fd6a691 commit 277a0ed

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@
185185
"uuid": "99408193-d0ce-4c68-8cab-e680f3ed56a4",
186186
"practices": [],
187187
"prerequisites": [],
188-
"difficulty": 2,
189-
"status": "wip"
188+
"difficulty": 2
190189
},
191190
{
192191
"slug": "hello-world",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## Maximum integer value
2+
3+
According to [the Vim docs][number]:
4+
5+
> Assuming 64 bit numbers are used (see v:numbersize) an unsigned number is truncated to 0x7fffffffffffffff or 9223372036854775807.
6+
7+
That means that Vim cannot express any number `2^63` or greater as an integer.
8+
9+
For the purposes of this exercise, we will declare that in Vimland, chess boards are 7x7 and have **49** squares.
10+
11+
[number]: https://vimhelp.org/eval.txt.html#expr-number
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function! Square(number) abort
2-
if a:number < 1 || a:number > 64
3-
throw 'square must be between 1 and 64'
2+
if a:number < 1 || a:number > 49
3+
throw 'square must be between 1 and 49'
44
endif
55

66
return float2nr(pow(2, (a:number-1)))
77
endfunction
88

99
function! Total() abort
10-
return float2nr(pow(2, 64) - 1)
10+
return float2nr(pow(2, 49) - 1)
1111
endfunction

exercises/practice/grains/grains.vader

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,28 @@ Execute (grains on square 32):
2929
let g:expected = 2147483648
3030
AssertEqual g:expected, Square(g:square)
3131

32-
Execute (grains on square 64):
33-
let g:square = 64
34-
let g:expected = 9223372036854775807
32+
Execute (grains on square 49):
33+
let g:square = 49
34+
let g:expected = 281474976710656
3535
AssertEqual g:expected, Square(g:square)
3636

3737
Execute (square 0 is invalid):
3838
let g:square = 0
39-
let g:expected = "square must be between 1 and 64"
39+
let g:expected = "square must be between 1 and 49"
4040
AssertThrows call Square(g:square)
4141
AssertEqual g:expected, g:vader_exception
4242

4343
Execute (negative square is invalid):
4444
let g:square = -1
45-
let g:expected = "square must be between 1 and 64"
45+
let g:expected = "square must be between 1 and 49"
4646
AssertThrows call Square(g:square)
4747
AssertEqual g:expected, g:vader_exception
4848

49-
Execute (square greater than 64 is invalid):
50-
let g:square = 65
51-
let g:expected = "square must be between 1 and 64"
49+
Execute (square greater than 49 is invalid):
50+
let g:square = 50
51+
let g:expected = "square must be between 1 and 49"
5252
AssertThrows call Square(g:square)
5353
AssertEqual g:expected, g:vader_exception
54-
5554
Execute (returns the total number of grains on the board):
56-
let g:expected = 9223372036854775807
55+
let g:expected = 562949953421311
5756
AssertEqual g:expected, Total()

exercises/practice/grains/grains.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"
22
" Returns the number of grains on a chessboard square given the grains on each square
33
" double from the previous square.
4-
" Throws an error if the square is below 1 or above 64.
4+
" Throws an error if the square is below 1 or above 49.
55
"
66
" Examples:
77
"
88
" :echo Square(16)
99
" 32768
1010
"
1111
" :echo Square(-1)
12-
" E605: Exception not caught: square must be between 1 and 64
12+
" E605: Exception not caught: square must be between 1 and 49
1313
"
1414
function! Square(number) abort
1515
" your code goes here

0 commit comments

Comments
 (0)