-
-
Save nishidy/f642c3377578eae600a4296be123d613 to your computer and use it in GitHub Desktop.
Google Code Jam 2016 Qualification Round : Problem A. Counting Sheep
This file contains 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
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