Skip to content

Instantly share code, notes, and snippets.

@nishidy nishidy/a.hs
Created May 6, 2016

Embed
What would you like to do?
Google Code Jam 2016 Qualification Round : Problem A. Counting Sheep
import Data.List
import Debug.Trace
import Control.Applicative
testloop :: Integer -> Integer -> IO String
testloop n t | n>t = return ""
testloop n t = getLine >>= teststr >>= \x->return ("Case #"++(show n)++": "++x) >>= putStrLn >> testloop (n+1) t
teststr :: String -> IO String
teststr s = disp $ dropWhile check0to9 $ concatnums $ numlist 1 s
numlist :: Integer -> String -> [String]
numlist n s | n < 1000 =
--trace("Debug[1]: "++x) (x:xs)
x:xs
where
x = show $ (*n) $ read s
xs= numlist (n+1) s
numlist n s = []
concatnums :: [String] -> [[String]]
concatnums xs = scanl (\x y->x++y:[]) [] xs
check0to9 :: [String] -> Bool
check0to9 s = case sort $ nub $ concat s of
-- "0123456789" -> trace("Debug[2]: "++(concat s)) (False)
-- _ -> trace("Debug[2]: "++(concat s)) (True)
"0123456789" -> False
_ -> True
disp :: [[String]] -> IO String
disp (x:xs) = return $ last x
disp ([]) = return "INSOMNIA"
main = getLine >>= \x-> testloop 1 $ read x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.