diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-02 22:11:43 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-02 22:11:43 +0100 |
| commit | 25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d (patch) | |
| tree | 6c76cce36b5db283bc17c8e041453c8852c32d9b /challenge-285/ulrich-rieke/haskell | |
| parent | 5700092f38ceae57dc000f4f9538207779dcf643 (diff) | |
| download | perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.tar.gz perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.tar.bz2 perlweeklychallenge-club-25b6f89a6bbb4860b072d2f20ab72d6f4e4aa57d.zip | |
- Added solutions by Ulrich Rieke.
- Added solutions by Paulo Custodio.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
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
|
