Last active
October 20, 2015 04:36
-
-
Save spencerjanssen/ccfc569cdbed7b3b168a to your computer and use it in GitHub Desktop.
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
import System.Environment | |
import Data.List (intercalate) | |
killEvery :: Int -> Int -> [a] -> [a] | |
killEvery n start = go start | |
where | |
go 0 (_:xs) = go (pred n) xs | |
go i (x:xs) = x : go (pred i) xs | |
go _ [] = [] | |
lucky :: [Int] | |
lucky = 1 : go 2 [3, 5 ..] | |
where | |
go idx (x:xs) = x : go (succ idx) (killEvery x (x-idx-1) xs) | |
sample n = takeWhile (< n) lucky | |
csv xs = intercalate "," $ map (show . show) xs | |
main = do | |
as <- getArgs | |
case as of | |
["--until", n] -> do | |
putStr . unlines . map show $ sample (read n) | |
[] -> do | |
putStr . unlines . map show $ lucky |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment