Created
April 8, 2016 14:31
-
-
Save hyuki0000/2cd332c77c2fd8dc85e3f9b9ea02bd58 to your computer and use it in GitHub Desktop.
von Neumann Integer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Web連載「数学ガールの秘密ノート」第151回 3を作ろう(前編)
https://cakes.mu/posts/12710