fork download
  1. type Odds = [Odd]
  2. data Odd = One | Three | Five | Seven | Nine deriving (Eq, Enum, Bounded)
  3.  
  4. one :: Odds
  5. one = [minBound]
  6.  
  7. instance Show Odd where
  8. show One = "1"
  9. show Three = "3"
  10. show Five = "5"
  11. show Seven = "7"
  12. show Nine = "9"
  13.  
  14. showOdds :: Odds -> String
  15. showOdds = concatMap show
  16.  
  17. inc :: Odds -> Odds
  18. inc xs = case foldr f ([], True) xs of
  19. (acc, True) -> minBound : acc
  20. (acc, _) -> acc
  21. where
  22. f x (acc, True) | x == maxBound = (minBound : acc, True)
  23. | otherwise = (succ x : acc, False)
  24. f x (acc, _) = (x : acc, False)
  25.  
  26. main :: IO ()
  27. main = print . takeWhile (<=1000) . map (read . showOdds) $ iterate inc one
  28.  
Success #stdin #stdout 0s 6288KB
stdin
Standard input is empty
stdout
[1,3,5,7,9,11,13,15,17,19,31,33,35,37,39,51,53,55,57,59,71,73,75,77,79,91,93,95,97,99,111,113,115,117,119,131,133,135,137,139,151,153,155,157,159,171,173,175,177,179,191,193,195,197,199,311,313,315,317,319,331,333,335,337,339,351,353,355,357,359,371,373,375,377,379,391,393,395,397,399,511,513,515,517,519,531,533,535,537,539,551,553,555,557,559,571,573,575,577,579,591,593,595,597,599,711,713,715,717,719,731,733,735,737,739,751,753,755,757,759,771,773,775,777,779,791,793,795,797,799,911,913,915,917,919,931,933,935,937,939,951,953,955,957,959,971,973,975,977,979,991,993,995,997,999]