diff --git a/config.json b/config.json index 2f2c238..2672181 100644 --- a/config.json +++ b/config.json @@ -185,8 +185,7 @@ "uuid": "99408193-d0ce-4c68-8cab-e680f3ed56a4", "practices": [], "prerequisites": [], - "difficulty": 2, - "status": "wip" + "difficulty": 2 }, { "slug": "hello-world", diff --git a/exercises/practice/grains/.docs/instructions.append.md b/exercises/practice/grains/.docs/instructions.append.md new file mode 100644 index 0000000..0135f08 --- /dev/null +++ b/exercises/practice/grains/.docs/instructions.append.md @@ -0,0 +1,11 @@ +## Maximum integer value + +According to [the Vim docs][number]: + +> Assuming 64 bit numbers are used (see v:numbersize) an unsigned number is truncated to 0x7fffffffffffffff or 9223372036854775807. + +That means that Vim cannot express any number `2^63` or greater as an integer. + +For the purposes of this exercise, we will declare that in Vimland, chess boards are 7x7 and have **49** squares. + +[number]: https://vimhelp.org/eval.txt.html#expr-number diff --git a/exercises/practice/grains/.meta/example.vim b/exercises/practice/grains/.meta/example.vim index 2848401..d68bac7 100644 --- a/exercises/practice/grains/.meta/example.vim +++ b/exercises/practice/grains/.meta/example.vim @@ -1,11 +1,11 @@ function! Square(number) abort - if a:number < 1 || a:number > 64 - throw 'square must be between 1 and 64' + if a:number < 1 || a:number > 49 + throw 'square must be between 1 and 49' endif return float2nr(pow(2, (a:number-1))) endfunction function! Total() abort - return float2nr(pow(2, 64) - 1) + return float2nr(pow(2, 49) - 1) endfunction diff --git a/exercises/practice/grains/grains.vader b/exercises/practice/grains/grains.vader index e2d44a2..e69b4bf 100644 --- a/exercises/practice/grains/grains.vader +++ b/exercises/practice/grains/grains.vader @@ -29,29 +29,28 @@ Execute (grains on square 32): let g:expected = 2147483648 AssertEqual g:expected, Square(g:square) -Execute (grains on square 64): - let g:square = 64 - let g:expected = 9223372036854775807 +Execute (grains on square 49): + let g:square = 49 + let g:expected = 281474976710656 AssertEqual g:expected, Square(g:square) Execute (square 0 is invalid): let g:square = 0 - let g:expected = "square must be between 1 and 64" + let g:expected = "square must be between 1 and 49" AssertThrows call Square(g:square) AssertEqual g:expected, g:vader_exception Execute (negative square is invalid): let g:square = -1 - let g:expected = "square must be between 1 and 64" + let g:expected = "square must be between 1 and 49" AssertThrows call Square(g:square) AssertEqual g:expected, g:vader_exception -Execute (square greater than 64 is invalid): - let g:square = 65 - let g:expected = "square must be between 1 and 64" +Execute (square greater than 49 is invalid): + let g:square = 50 + let g:expected = "square must be between 1 and 49" AssertThrows call Square(g:square) AssertEqual g:expected, g:vader_exception - Execute (returns the total number of grains on the board): - let g:expected = 9223372036854775807 + let g:expected = 562949953421311 AssertEqual g:expected, Total() diff --git a/exercises/practice/grains/grains.vim b/exercises/practice/grains/grains.vim index 7453bcf..859b744 100644 --- a/exercises/practice/grains/grains.vim +++ b/exercises/practice/grains/grains.vim @@ -1,7 +1,7 @@ " " Returns the number of grains on a chessboard square given the grains on each square " double from the previous square. -" Throws an error if the square is below 1 or above 64. +" Throws an error if the square is below 1 or above 49. " " Examples: " @@ -9,7 +9,7 @@ " 32768 " " :echo Square(-1) -" E605: Exception not caught: square must be between 1 and 64 +" E605: Exception not caught: square must be between 1 and 49 " function! Square(number) abort " your code goes here