Created
July 10, 2018 16:03
-
-
Save vxgmichel/5f3cfc69e06dd149d6bc188a58f949cd to your computer and use it in GitHub Desktop.
Solve the 'Infinite House of Pancakes' problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Solve the 'Infinite House of Pancakes' problem. | |
-- https://code.google.com/codejam/contest/6224486/dashboard#s=p1 | |
import Text.Printf | |
-- Generic solver code | |
main :: IO () | |
main = interact | |
$ unlines . cases . map (format . solve) . parse . tail . lines | |
where cases = zipWith (printf "Case #%d: %s") [1::Int ..] | |
-- Problem-specific code | |
parse :: [String] -> [[Int]] | |
parse [] = [] | |
parse (_:x:xs) = (map read . words $ x) : parse xs | |
solve :: [Int] -> Int | |
solve s = minimum [test l s | l <- [1 .. maximum s]] | |
where test l = (+l) . sum . map (cost l) | |
where cost l = (`div` l) . subtract 1 | |
format :: Int -> String | |
format = show |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We can whittle closer to
parse
's varying core: