Skip to content

Instantly share code, notes, and snippets.

@inopinatus
Created June 1, 2018 11:38
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 inopinatus/1d79395d74a3ddee14c2149c5c1cb7fa to your computer and use it in GitHub Desktop.
Save inopinatus/1d79395d74a3ddee14c2149c5c1cb7fa to your computer and use it in GitHub Desktop.
Ackermann function in one line of Ruby as a hash default proc
A = Hash.new { |a,(m,n)| a[[m,n]] = m==0 ? n+1 : n==0 ? a[[m-1,1]] : a[[m-1, a[[m, n-1]]]] } #=> {}
A[[3,4]] #=> 125
A.inspect #=> ... long
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment