Browse files

completed #17

  • Loading branch information...
1 parent e7d5bdc commit 4a7efee421fe276b32e19609ea77bcc2100faed2 Eric Wilson committed Feb 4, 2011
Showing with 18 additions and 21 deletions.
  1. +17 −20 017.hs
  2. +1 −1 README
View
37 017.hs
@@ -6,10 +6,22 @@ teenWords = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixt
tensConnect = ("", "-")
hundredsConnect = (" hundred", " and ")
-thousandsConnect = (" thousand", " , ")
+thousandsConnect = (" thousand", ", ")
-digitsToWords :: (Int, Int, Int) -> (String, String, String)
-digitsToWords (h, t, o) = (onesWords !! h, tensWords !! t, onesWords !! o)
+-- Works up to 999,999. Wouldn't take much to extend it much beyond that.
+sayIt :: Int -> String
+sayIt n = connect first second thousandsConnect
+ where
+ first = list !! 0
+ second = list !! 1
+ list = thousandsList n
+
+thousandsList :: Int -> [String]
+thousandsList = map threeDigitsToWords . commas
+ where
+ commas n = quot n 1000 : [mod n 1000]
+ threeDigitsToWords = tripleToWords . makeTriple
+ makeTriple n = (quot n 100, (mod (quot n 10) 10, mod n 10))
doubleToWords :: (Int, Int) -> String
doubleToWords (t, o)
@@ -24,25 +36,10 @@ connect "" second connect = second
connect first "" connect = first ++ fst connect
connect first second connect = first ++ fst connect ++ snd connect ++ second
-makeTriple :: Int -> (Int, (Int, Int))
-makeTriple n = (quot n 100, (mod (quot n 10) 10, mod n 10))
-
-threeDigitsToWords :: Int -> String
-threeDigitsToWords = tripleToWords . makeTriple
-
-commas :: Int -> [Int]
-commas 0 = []
-commas n = mod n 1000 : (commas $ quot n 1000)
-
-sayIt :: Int -> String
-sayIt n = "num-ber ,"
-
-countTo :: Int -> [String]
-countTo n = map sayIt [1..n]
-
totalLetters :: [String] -> Int
totalLetters words = sum $ map lettersInString words
where lettersInString = length . filter isLetter
euler17 :: Int -> Int
-euler17 = totalLetters . countTo
+euler17 = totalLetters . countTo
+ where countTo n = map sayIt [1..n]
View
2 README
@@ -19,6 +19,6 @@ Here's the current status: (No status listed if no code is checked in.)
#14: Some exploratory work
#15: SOLVED
#16: SOLVED
-#17: Nearly complete
+#17: SOLVED
#19: SOLVED
#20: SOLVED

0 comments on commit 4a7efee

Please sign in to comment.