Skip to content

Instantly share code, notes, and snippets.

@spencerjanssen
Last active October 20, 2015 04:36
Show Gist options
  • Save spencerjanssen/ccfc569cdbed7b3b168a to your computer and use it in GitHub Desktop.
Save spencerjanssen/ccfc569cdbed7b3b168a to your computer and use it in GitHub Desktop.
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