Skip to content

Instantly share code, notes, and snippets.

@yoppi
Created June 1, 2011 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoppi/1001608 to your computer and use it in GitHub Desktop.
Save yoppi/1001608 to your computer and use it in GitHub Desktop.
Recursive Function with Vim Script
function! Tree(lst, ret)
if empty(a:lst)
return a:ret
endif
let _ = a:ret + get(a:lst, 0)
return Tree(a:lst[1:-1], _)
endfunction
echo Tree(range(11), 0)
"=> 55
@henrynguyen6677
Copy link

let s:scoreMap = {
  \'A': 1, 'E': 1, 'I': 1, 'O': 1, 'U': 1, 'L': 1, 'N': 1, 'R': 1, 'S': 1, 'T': 1,
  \'D': 2, 'G': 2,
  \'B': 3, 'C': 3, 'M': 3, 'P': 3,
  \'F': 4, 'H': 4, 'V': 4, 'W': 4, 'Y': 4,
  \'K': 5,
  \'J': 8, 'X': 8,
  \'Q': 10, 'Z': 10
\}


function! Score(word) abort
  return empty(a:word) ? 0 : Score(a:word[1:]) + s:scoreMap[toupper(a:word[0])]
endfunction

echo Score('abc') "=> 7

Solution: https://exercism.io/tracks/vimscript/exercises/scrabble-score/solutions/b3b78881542c467896ffc4b73e029542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment