Skip to content

Instantly share code, notes, and snippets.

@dmalikov
Created November 28, 2011 16:54
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 dmalikov/1401073 to your computer and use it in GitHub Desktop.
Save dmalikov/1401073 to your computer and use it in GitHub Desktop.
Project Euler 206 (1 s)
import Data.List (find)
import Control.Monad (replicateM)
import Data.Maybe (fromJust)
import Numeric (showFFloat)
isSquare :: Integer -> Bool
isSquare x = x'*x' == x
where x' = truncate $ sqrt (fromIntegral x :: Double)
sew :: [Integer] -> Integer
sew = foldl1 ((+).(*10)) . (++ [9,0,0]) . concatMap (uncurry ((. return) . (:))) . zip [1..]
main = print $ showFFloat (Just 0) (sqrt . fromIntegral . fromJust . find isSquare . map sew $ replicateM 8 [9,8..0]) ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment