Skip to content

Instantly share code, notes, and snippets.

@JohnMorales
Created October 19, 2013 12:42
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 JohnMorales/7055283 to your computer and use it in GitHub Desktop.
Save JohnMorales/7055283 to your computer and use it in GitHub Desktop.
require './zlorpian'
# Good afternoon fellow space travelers, thanks for coming along on this mission. We still have about a week
# before we arrive at New Zlorpia, so please return your stasis tubes to their original upright position and
# prepare for your mission briefing.
# We are going to be negotiating a trade agreement with the Zlorpians for their supply of Farkle seeds. They
# have a much different way of counting than we do, and I'm concerned that if we don't have a good way to
# work with their number system, we'll be at a disadvantage in negotiations. Let me explain:
# The zlorpians have a single arm that comes out of their forehead, with a hand that has 3 fingers. As a
# result, our base-10 way of counting (based on our ten fingers) is as alien to them as their way is to us.
# In some ways, their numbering system is similar to ours.
# They represent the value zero with a single horizontal dash, and call it "zlorp".
# The represent the number one with a single vertical dash, and it it "borp".
# The number 2 is represented with 2 crossed lines, similar to our letter "X", and is called a "daborp".
# Their number 3 is represented with a hash of three lines... the closest character on our keyboards is "#",
# and is called a traborp.
# And thats it. They only represent the numbers 0-3.
# BUT, just like us, they use columns to represent bigger numbers, 'rolling over' into the next column when
# it gets too big. Counting this way, their numbers look like this:
# -
# |
# X
# #
# |-
# ||
# |X
# |#
# X-
# X|
# XX
# X#
# #-
# #|
# #X
# ##
# |--
# Thankfully, they also have a really predictable way of naming each of the columns. When there is only one
# column, the numbers are pronounced exactly as we define them above. When there is a second column, called
# the 'ity' column, they add the ending 'ity' to the name of the number. So the number "||" is called
# "Borpityborp". The number "X#" is called "Daborpitytraborp". By convention, if the number in the last
# column is a zlorp, as in "|-", then they drop the zlorp, simply calling it "borpity". This same pattern
# holds for as many columns as we have learned to translate.
# the rightmost column does not modify the number's name, as we have already seen.
# the second-rightmost column is named "ity", as we have already seen.
# The third-rightmost is named "en"
# the fourth rightmost is named "onk"
# the fifth rightmost is named "iffa"
# Your job is to write 2 functions. The first one should take a decimal number and convert it to a zlorpinumeral.
# It should work like this:
describe "#zlorpinumeral" do
it "converts 0" do
zlorpinumeral(0).should eql "-"
end
it "converts 1" do
zlorpinumeral(1).should eql "|"
end
it "converts 2" do
zlorpinumeral(2).should eql "X"
end
it "converts 3" do
zlorpinumeral(3).should eql "#"
end
it "converts 4" do
zlorpinumeral(4).should eql "|-"
end
it "converts 5" do
zlorpinumeral(5).should eql "||"
end
it "converts 15" do
zlorpinumeral(15).should eql "##"
end
it "converts 16" do
zlorpinumeral(16).should eql "|--"
end
it "converts 17" do
zlorpinumeral(17).should eql "|-|"
end
it "converts 200" do
zlorpinumeral(200).should eql "#-X-"
end
it "converts 221" do
zlorpinumeral(221).should eql "#|#|"
end
it "converts 237" do
zlorpinumeral(237).should eql "#X#|"
end
it "converts 1001" do
zlorpinumeral(1001).should eql "##XX|"
end
end
# The second one should convert a decimal number to zlorpanese. It should work like this:
describe "#zlorpanese" do
it "converts 0" do
zlorpianese(0).should eql "zlorp"
end
it "converts 1" do
zlorpianese(1).should eql "borp"
end
it "converts 2" do
zlorpianese(2).should eql "daborp"
end
it "converts 3" do
zlorpianese(3).should eql "traborp"
end
it "converts 4" do
zlorpianese(4).should eql "borpity"
end
it "converts 5" do
zlorpianese(5).should eql "borpityborp"
end
it "converts 7" do
zlorpianese(7).should eql "borpitytraborp"
end
it "converts 8" do
zlorpianese(8).should eql "daborpity"
end
it "converts 9" do
zlorpianese(9).should eql "daborpityborp"
end
it "converts 10" do
zlorpianese(10).should eql "daborpitydaborp"
end
it "converts 15" do
zlorpianese(15).should eql "traborpitytraborp"
end
it "converts 16" do
zlorpianese(16).should eql "borpen"
end
it "converts 17" do
zlorpianese(17).should eql "borpenborp"
end
it "converts 21" do
zlorpianese(21).should eql "borpenborpityborp"
end
it "converts 200" do
zlorpianese(200).should eql "traborponkdaborpity"
end
it "converts 221" do
zlorpianese(221).should eql "traborponkborpentraborpityborp"
end
it "converts 237" do
zlorpianese(237).should eql "traborponkdaborpentraborpityborp"
end
it "converts 1001" do
zlorpianese(1001).should eql "traborpiffatraborponkdaborpendaborpityborp"
end
end
# If as a side effect you have functions that convert a zorpinumeral to a zorpanese string, please share them.
# Extra points for the ability to convert a zorpinumeral back to a decimal number.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment