Skip to content

Instantly share code, notes, and snippets.

@todashuta
Last active January 2, 2016 02:39
Show Gist options
  • Save todashuta/8238878 to your computer and use it in GitHub Desktop.
Save todashuta/8238878 to your computer and use it in GitHub Desktop.
Vim script でアッカーマン関数
" Vim script でアッカーマン関数
function! s:ack(m, n)
if a:m == 0
return a:n + 1
elseif a:n == 0
return s:ack(a:m - 1, 1)
else
return s:ack(a:m - 1, s:ack(a:m, a:n - 1))
endif
endfunction
" s:ack(3, 4) を実行するのに必要な maxfuncdepth を求めてみる
for s:i in reverse(range(100, 150))
let &maxfuncdepth = s:i
try
call s:ack(3, 4) " => 125
echo printf('maxfuncdepth=%d OK.', s:i)
catch
echo printf('maxfuncdepth=%d Failed.', s:i)
break
endtry
endfor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment