Skip to content

Instantly share code, notes, and snippets.

@hyuki0000
Created April 8, 2016 14:31
Show Gist options
  • Save hyuki0000/2cd332c77c2fd8dc85e3f9b9ea02bd58 to your computer and use it in GitHub Desktop.
Save hyuki0000/2cd332c77c2fd8dc85e3f9b9ea02bd58 to your computer and use it in GitHub Desktop.
von Neumann Integer.
class Fixnum
def to_ss
if self == 0
""
elsif self == 1
"{}"
else
(self - 1).to_ss + ',' + (self - 1).to_s
end
end
def to_s
"{" + self.to_ss + "}"
end
end
puts 0 # => {}
puts 1 # => {{}}
puts 2 # => {{},{{}}}
puts 3 # => {{},{{}},{{},{{}}}}
puts -1 # => stack level too deep (SystemStackError)
@hyuki0000
Copy link
Author

Web連載「数学ガールの秘密ノート」第151回 3を作ろう(前編)
https://cakes.mu/posts/12710

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