Skip to content

Instantly share code, notes, and snippets.

@sbjustin
Last active December 25, 2015 16:59
Show Gist options
  • Save sbjustin/7009514 to your computer and use it in GitHub Desktop.
Save sbjustin/7009514 to your computer and use it in GitHub Desktop.
Zlorpian to decimal - Answer to @bokmann's puzzle found at https://gist.github.com/bokmann/6985516
class Numeric
def to_zlorp(zlorp = "")
case self
when 0
zlorp << "-"
when 1
zlorp << "|"
when 2
zlorp << "X"
when 3
zlorp << "#"
else
(self%4).to_zlorp(zlorp)
(self/4).to_zlorp(zlorp)
end
zlorp.reverse
end
def to_zlorpanese
zlorp = self.build_zlorpanese
zlorp = zlorp.reverse
while zlorp.length > 1 && zlorp.last.match(/zlorp[.+]?/)
zlorp.pop
end
zlorp.join
end
def build_zlorpanese(zlorp = [], count = 0 )
case self
when 0
zlorp << "zlorp" + ["", "ity", "en", "onk", "iffa"][count]
when 1
zlorp << "borp" + ["", "ity", "en", "onk", "iffa"][count]
when 2
zlorp << "daborp" + ["", "ity", "en", "onk", "iffa"][count]
when 3
zlorp << "traborp" + ["", "ity", "en", "onk", "iffa"][count]
else
(self%4).build_zlorpanese(zlorp, zlorp.length)
(self/4).build_zlorpanese(zlorp, zlorp.length)
end
end
end
puts "to_zlorp"
puts 0.to_zlorp == "-"
puts 1.to_zlorp == "|"
puts 2.to_zlorp == "X"
puts 3.to_zlorp == "#"
puts 4.to_zlorp == "|-"
puts 5.to_zlorp == "||"
puts 15.to_zlorp == "##"
puts 16.to_zlorp == "|--"
puts 17.to_zlorp == "|-|"
puts 21.to_zlorp == "|||"
puts 200.to_zlorp == "#-X-"
puts 221.to_zlorp == "#|#|"
puts 237.to_zlorp == "#X#|"
puts 1001.to_zlorp == "##XX|"
puts "to_zlorpanese"
puts 0.to_zlorpanese == "zlorp"
puts 1.to_zlorpanese == "borp"
puts 2.to_zlorpanese == "daborp"
puts 3.to_zlorpanese == "traborp"
puts 4.to_zlorpanese == "borpity"
puts 5.to_zlorpanese == "borpityborp"
puts 6.to_zlorpanese == "borpitydaborp"
puts 7.to_zlorpanese == "borpitytraborp"
puts 8.to_zlorpanese == "daborpity"
puts 9.to_zlorpanese == "daborpityborp"
puts 10.to_zlorpanese == "daborpitydaborp"
puts 15.to_zlorpanese == "traborpitytraborp"
puts 16.to_zlorpanese == "borpen"
puts 17.to_zlorpanese == "borpenborp"
puts 21.to_zlorpanese == "borpenborpityborp"
puts 200.to_zlorpanese == "traborponkdaborpity"
puts 221.to_zlorpanese == "traborponkborpentraborpityborp"
puts 237.to_zlorpanese == "traborponkdaborpentraborpityborp"
puts 1001.to_zlorpanese == "traborpiffatraborponkdaborpendaborpityborp"
# 0 - zlorp
# 1 | borp
# 2 X daborp
# 3 # traborp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment