diff options
Diffstat (limited to 'challenge-285/ulrich-rieke/haskell')
| -rwxr-xr-x | challenge-285/ulrich-rieke/haskell/ch-1.hs | 19 | ||||
| -rwxr-xr-x | challenge-285/ulrich-rieke/haskell/ch-2.hs | 16 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-285/ulrich-rieke/haskell/ch-1.hs b/challenge-285/ulrich-rieke/haskell/ch-1.hs new file mode 100755 index 0000000000..0ddcd35d73 --- /dev/null +++ b/challenge-285/ulrich-rieke/haskell/ch-1.hs @@ -0,0 +1,19 @@ +module Challenge285
+ where
+import Data.List.Split ( splitOn )
+
+solution :: String -> String
+solution input =
+ let routes = splitOn "," input
+ routepairs = map (\li -> (head li , last li ) ) $ map ( concat .
+ splitOn " " ) routes
+ starts = map fst routepairs
+ destinations = map snd routepairs
+ in filter (\dest -> notElem dest starts ) destinations
+
+main :: IO ( )
+main = do
+ putStrLn "Enter some routes, separated by ','!"
+ putStrLn "Separate start and destination by a blank!"
+ allRoutes <- getLine
+ print $ solution allRoutes
diff --git a/challenge-285/ulrich-rieke/haskell/ch-2.hs b/challenge-285/ulrich-rieke/haskell/ch-2.hs new file mode 100755 index 0000000000..e17bc8f81f --- /dev/null +++ b/challenge-285/ulrich-rieke/haskell/ch-2.hs @@ -0,0 +1,16 @@ +module Challenge285_2
+ where
+
+denominations :: [Int]
+denominations = [50, 25 , 10 , 5 , 1]
+
+findCoinCombis :: [Int] -> Int -> [[Int]]
+findCoinCombis [1] n = [[n]]
+findCoinCombis ( den:rest ) n = [c:cs | c <- [0..div n den] , cs <-
+ findCoinCombis rest ( n - c * den )]
+
+main :: IO ( )
+main = do
+ putStrLn "Enter an amount of money in pennies!"
+ amount <- getLine
+ print $ length $ findCoinCombis denominations $ read amount
|
