Skip to content

Instantly share code, notes, and snippets.

@k16shikano
Created January 3, 2020 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k16shikano/ec196f79a439836a87bd375802ee9616 to your computer and use it in GitHub Desktop.
Save k16shikano/ec196f79a439836a87bd375802ee9616 to your computer and use it in GitHub Desktop.
module Main where
import System.Environment (getArgs)
import System.Random
import Data.List
scan2020 :: [Int] -> [[Int]]
scan2020 [] = []
scan2020 ls@(x:xs)
| isPrefixOf the2020 ls = the2020 : (scan2020 $ drop 4 ls)
| otherwise = [x] : scan2020 xs
where the2020 = [2, 0, 2, 0]
hl2020 :: [[Int]] -> [String]
hl2020 [] = []
hl2020 (x:xs)
| length x == 4 =
concat ["\ESC[31m", intercalate " " $ map show x, "\ESC[m"] : hl2020 xs
| otherwise = concatMap show x : hl2020 xs
main :: IO ()
main = do
a <- fmap (read . head) getArgs
s <- getStdGen
putStrLn $ intercalate " " $ hl2020 $ take a $ scan2020 $ twoandzero s
where
twoandzero s = map ((*2) . flip mod 2) (randoms s :: [Int])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment