first commit

This commit is contained in:
Thorn Avery 2021-03-12 14:44:46 +13:00
commit 448981d4d8
3 changed files with 34 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.hi
*.o
*.swp
eggdrop

1
README.md Normal file
View File

@ -0,0 +1 @@
solution for the eggdrop problem

29
egg.hs Normal file
View File

@ -0,0 +1,29 @@
import Data.Map (Map, (!))
import qualified Data.Map as Map
loeb :: Functor f => f (f a -> a) -> f a
loeb x = go where go = fmap ($ go) x
loebify :: Integer -> Integer -> (Map (Integer, Integer) Integer -> Integer)
loebify n k
| k == 1 || k == 0 || n == 1 = const k
| otherwise = (\m -> 1 + (minimum $ map (\i -> f m i) [1..k]))
where
f m i = max (m ! ((n-1),(i-1))) (m ! (n,(k-i)))
solve :: Integer -> Integer -> Integer
solve n k = (loeb m) ! (n,k)
where
f (n,k) = ((n,k), loebify n k)
m = Map.fromList $ map f [ (x,y) | x <- [1..n], y <- [0..k]]
-----------------
-- gross io bs --
-----------------
main :: IO ()
main = do
l <- getLine
let (n:k:_) = map read $ words l :: [Integer]
putStrLn $ show $ solve n k