Babbage problem: Difference between revisions

Content deleted Content added
Hout (talk | contribs)
Hout (talk | contribs)
→‎Haskell Suffixes and integer roots: More intelligible output lines (by switching pairs from tuples to x:[y])
Line 924:
 
<lang haskell>import Data.List (intercalate)
 
babbagePairs :: [([Integer, Integer)]]
babbagePairs =
[0,1000000 ..] >>= -- Drawing from a succession of N * 10^6
\x ->
let y = (x + 269696) -- The next number ending in 269696,
r = (sqrt . fromIntegral) y -- its square root,
i = floor r -- and the integer part of that root.
in [ ([i, y) ] -- Root and square harvested together,
| r == fromIntegral i ] -- only if that root is an integer.
]
 
main :: IO ()
main = do
let arrowed = intercalate " -> " . fmap show
(putStrLn . unlines) $
mapM_ putStrLn (arrowed <$> take 10 babbagePairs)</lang>
fmap
(intercalate " -> " . fmap show . (pure (:) <*> fst <*> (return . snd)))
(take 10 babbagePairs)</lang>
{{Out}}
<pre>25264 -> 638269696