• API
• FAQ
• Tools
• Trends
• Archive
SHARE
TWEET

# Untitled

a guest Feb 28th, 2012 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # Works from 1 - 999
2. # Recursively convert to cardinal numbers
3. def cardinal(num)
4.   case num
5.     when 0  then return ""
6.     when 1  then return "one"
7.     when 2  then return "two"
8.     when 3  then return "three"
9.     when 4  then return "four"
10.     when 5  then return "five"
11.     when 6  then return "six"
12.     when 7  then return "seven"
13.     when 8  then return "eight"
14.     when 9  then return "nine"
15.     when 10 then return "ten"
16.     when 11 then return "eleven"
17.     when 12 then return "twelve"
18.     when 13 then return "thirteen"
19.     when 14 then return "fourteen"
20.     when 15 then return "fifteen"
21.     when 16 then return "sixteen"
22.     when 17 then return "seventeen"
23.     when 18 then return "eighteen"
24.     when 19 then return "nineteen"
25.   end
26.
27.   return "twenty"   + cardinal(num-20) if (num < 30)
28.   return "thirty"   + cardinal(num-30) if (num < 40)
29.   return "forty"    + cardinal(num-40) if (num < 50)
30.   return "fifty"    + cardinal(num-50) if (num < 60)
31.   return "sixty"    + cardinal(num-60) if (num < 70)
32.   return "seventy"  + cardinal(num-70) if (num < 80)
33.   return "eighty"   + cardinal(num-80) if (num < 90)
34.   return "ninety"   + cardinal(num-90) if (num < 100)
35.
36.   return cardinal(num/100) + "hundred" + cardinal(num%100)
37. end
38.
39. # Works from 1 - 999999
40. # Recursively convert to ordinal numbers
41. def ordinal(num)
42.   case num
43.                 when 0  then return ""
44.                 when 1  then return "first"
45.                 when 2  then return "second"
46.                 when 3  then return "third"
47.                 when 4  then return "fourth"
48.                 when 5  then return "fifth"
49.                 when 6  then return "sixth"
50.                 when 7  then return "seventh"
51.                 when 8  then return "eighth"
52.                 when 9  then return "ninth"
53.                 when 10 then return "tenth"
54.                 when 11 then return "eleventh"
55.                 when 12 then return "twelfth"
56.                 when 13 then return "thirteenth"
57.                 when 14 then return "fourteenth"
58.                 when 15 then return "fifteenth"
59.                 when 16 then return "sixteenth"
60.                 when 17 then return "seventeenth"
61.                 when 18 then return "eighteenth"
62.                 when 19 then return "nineteenth"
63.                 when 20 then return "twentieth"
64.                 when 30 then return "thirtieth"
65.                 when 40 then return "fortieth"
66.                 when 50 then return "fiftieth"
67.                 when 60 then return "sixtieth"
68.                 when 70 then return "seventieth"
69.                 when 80 then return "eightieth"
70.                 when 90 then return "ninetieth"
71.   end
72.
73.   return cardinal(20) + ordinal(num-20) if (num < 30)
74.   return cardinal(30) + ordinal(num-30) if (num < 40)
75.   return cardinal(40) + ordinal(num-40) if (num < 50)
76.   return cardinal(50) + ordinal(num-50) if (num < 60)
77.   return cardinal(60) + ordinal(num-60) if (num < 70)
78.   return cardinal(70) + ordinal(num-70) if (num < 80)
79.   return cardinal(80) + ordinal(num-80) if (num < 90)
80.   return cardinal(90) + ordinal(num-90) if (num < 100)
81.
82.   return cardinal(num/100) + "hundredth" if (num < 1000) and (num % 100 == 0)
83.   return cardinal(num/100) + "hundred" + ordinal(num%100) if (num < 1000)
84.
85.   return cardinal(num/1000) + "thousandth" if (num % 1000 == 0)
86.   return cardinal(num/1000) + "thousand" + ordinal(num%1000)
87. end
88.
89. #862623
90. MAX = 100000
91.
92. # Store all aronsons in an array
93. aronsons = []
94. index = 0
95.
96. # Start the sentence
97. sentence = "tisthe"
99.
100. # Calculate all the aronson numbers
101. MAX.times do
102.   index = sentence.index(?t, index) + 1
103.
104.   sentence << ordinal(index) unless sentence.length > 1000000
105.
106.   aronsons << index
107. end
108.
109. #puts sentence
110. puts aronsons[MAX-1]
RAW Paste Data
Top