Skip to content

Instantly share code, notes, and snippets.

@stesla
Created February 16, 2010 23:54
Show Gist options
  • Save stesla/306094 to your computer and use it in GitHub Desktop.
Save stesla/306094 to your computer and use it in GitHub Desktop.
import Control.Monad (liftM)
import System.Environment (getArgs)
board = 16 * 12
cut :: Integer -> (Integer, Integer) -> (Integer, Integer)
cut 0 acc = acc
cut x (n, 0) = cut x (n + 1, board)
cut x (n, r) | x <= r = (n, r - x)
| x > board = cut (x - board) (n + 1, r)
| otherwise = cut x (n, 0)
splice :: [Integer] -> Integer
splice xs = let (boards, _) = foldr cut (0,0) xs in boards
main = do
measurements <- liftM parse getArgs
display (splice measurements)
where parse = map read
display = putStrLn . show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment