From 4f7544666a901098537e77edea0cb154f8fd4626 Mon Sep 17 00:00:00 2001 From: Glenn Jackman Date: Thu, 7 Nov 2024 22:08:26 -0500 Subject: [PATCH] give up on method notation to appease vint --- exercises/practice/grains/.meta/example.vim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exercises/practice/grains/.meta/example.vim b/exercises/practice/grains/.meta/example.vim index a6b21b4..c21ed49 100644 --- a/exercises/practice/grains/.meta/example.vim +++ b/exercises/practice/grains/.meta/example.vim @@ -1,24 +1,24 @@ " add two strings as numbers from right to left, as if by hand function! StringAdd(a, b) abort " zero-left-pad so the numbers are the same length - let len = [a:a->strlen(), a:b->strlen()]->max() + let len = max([strlen(a:a), strlen(a:b)]) let a = printf('%0*s', len, a:a) let b = printf('%0*s', len, a:b) let result = "" let carry = 0 for i in range(len - 1, 0, -1) - let c = carry + a->strpart(i, 1)->str2nr() + b->strpart(i, 1)->str2nr() + let c = carry + str2nr(strpart(a, i, 1)) + str2nr(strpart(b, i, 1)) let result = $"{c % 10}{result}" let carry = c / 10 endfor - return $"{carry}{result}"->trim('0', 1) + return trim($"{carry}{result}", '0', 1) endfunction " populate the squares, doubling each previous, cache in the script scope let s:grains = ['1'] for i in range(1, 63) - eval s:grains->add(StringAdd(s:grains[i - 1], s:grains[i - 1])) + eval add(s:grains, StringAdd(s:grains[i - 1], s:grains[i - 1])) endfor " return the grains on square `number`