Skip to content

Instantly share code, notes, and snippets.

@xnuk
Created July 2, 2015 16:32
Show Gist options
  • Save xnuk/3214b61382d3232adcbc to your computer and use it in GitHub Desktop.
Save xnuk/3214b61382d3232adcbc to your computer and use it in GitHub Desktop.
sq2 :: Integer -> Integer -> [Integer]
sq2 left divider = let a = takeWhile (<= left) [(divider+i)*i | i<-[1..9]]
in if null a
then 0:sq2 (left*100) (divider*10)
else fromIntegral (length a):sq2 ((left - last a)*100) ((divider + fromIntegral (length a) * 2)*10)
main :: IO ()
main = print (sqrt (2 :: Double)) >> mapM_ (putStr . show) (sq2 2 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment