Closed glennj closed 2 weeks ago
I think we'd need to mark the affected tests as not included in tests.toml
. We're changing the descriptions, inputs, and expected values.
moving the PR to draft while I ponder the reimplementation.
vint is failing
exercises/practice/grains/.meta/example.vim:4:17: unexpected token: -> (see vim-jp/vim-vimlparser)
Line 4 col 17 of the new example is
let len = [a:a->strlen(), a:b->strlen()]->max()
" ..............^
Is vint going to make me do
let len = max([strlen(a:a), strlen(a:b)])
I'm having trouble installing it locally:
$ python3 -m venv ~/python3
$ source ~/python3/bin/activate.fish
$ python3 -m pip install vim-vint
Collecting vim-vint
Downloading vim_vint-0.3.21-py2.py3-none-any.whl.metadata (910 bytes)
Collecting PyYAML>=3.11 (from vim-vint)
Downloading PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl.metadata (2.1 kB)
Collecting ansicolor>=0.2.4 (from vim-vint)
Downloading ansicolor-0.3.2-py2.py3-none-any.whl.metadata (625 bytes)
Collecting chardet>=2.3.0 (from vim-vint)
Downloading chardet-5.2.0-py3-none-any.whl.metadata (3.4 kB)
Downloading vim_vint-0.3.21-py2.py3-none-any.whl (89 kB)
Downloading ansicolor-0.3.2-py2.py3-none-any.whl (9.8 kB)
Downloading chardet-5.2.0-py3-none-any.whl (199 kB)
Downloading PyYAML-6.0.2-cp313-cp313-macosx_10_13_x86_64.whl (181 kB)
Installing collected packages: ansicolor, PyYAML, chardet, vim-vint
Successfully installed PyYAML-6.0.2 ansicolor-0.3.2 chardet-5.2.0 vim-vint-0.3.21
$ type -a vint
vint is /Users/glennj/python3/bin/vint
$ vint exercises/practice/grains/
Traceback (most recent call last):
File "/Users/glennj/python3/bin/vint", line 5, in <module>
from vint import main
File "/Users/glennj/python3/lib/python3.13/site-packages/vint/__init__.py", line 1, in <module>
from vint.bootstrap import (
...<3 lines>...
)
File "/Users/glennj/python3/lib/python3.13/site-packages/vint/bootstrap.py", line 5, in <module>
from vint.linting.cli import CLI
File "/Users/glennj/python3/lib/python3.13/site-packages/vint/linting/cli.py", line 4, in <module>
import pkg_resources
ModuleNotFoundError: No module named 'pkg_resources'
$ python3 -m pip install pkg_resources
ERROR: Could not find a version that satisfies the requirement pkg_resources (from versions: none)
ERROR: No matching distribution found for pkg_resources
OK, going to stop here. I'm shocked that "vimlparser" can't recognize method notation.
I’ll leave it up to Victor, but I’m not sure vint is useful here. Tests are automatically generated. The example solution just needs to pass the CI so I don’t bother using a linter on the other tracks I maintain.
OK, going to stop here. I'm shocked that "vimlparser" can't recognize method notation.
" Helper function to add two large numbers represented as strings
function! StringAdd(num1, num2)
let carry = 0
let result = ''
" Pad the shorter number with leading zeros
let len1 = strlen(a:num1)
let len2 = strlen(a:num2)
if len1 < len2
let a:num1 = repeat('0', len2 - len1) . a:num1
elseif len2 < len1
let a:num2 = repeat('0', len1 - len2) . a:num2
endif
" Add digits from right to left
for i in range(strlen(a:num1) - 1, 0, -1)
let sum = str2nr(a:num1[i]) + str2nr(a:num2[i]) + carry
let carry = sum >= 10 ? 1 : 0
let result = string(sum % 10) . result
endfor
" Add the last carry if it exists
if carry > 0
let result = '1' . result
endif
return result
endfunction
" Function to calculate grains on a specific square using string manipulation
function! Square(n)
if a:n < 1 || a:n > 64
throw 'square must be between 1 and 64'
endif
" Start with 1 grain on the first square
let grains = '1'
for i in range(2, a:n)
" Double the grains by adding it to itself
let grains = StringAdd(grains, grains)
endfor
return grains
endfunction
" Function to calculate the total grains on the chessboard using string manipulation
function! Total()
let total = '0'
" Accumulate grains for each square from 1 to 64
let grains = '1'
for i in range(1, 64)
let total = StringAdd(total, grains)
" Double grains for the next square
let grains = StringAdd(grains, grains)
endfor
return total
endfunction
This passes vint, and I believe should also satisfy past 64 locations, though of course we want to (probably) fail past 64 from the story parameters given.
Different approach, but let me know what you think.
Thanks @kotp that was driving me nuts
Ah sh!t, I accidentally deleted the branch. I'll create a new PR
http://forum.exercism.org/t/odd-arithmetic-in-grains/8662
Since the exercise was in WIP status, no worries about invalidating existing solutions.