Find square difference: Difference between revisions

Content added Content deleted
(Find square difference in Tiny BASIC)
m (→‎{{header|Haskell}}: Trivial edit to a trivial problem)
Line 329: Line 329:
-- Or, with redundant verbosity
-- Or, with redundant verbosity


g n =
g n = i
where
let Just i = findIndex (> n) [1, 3..]
Just i = succ <$> findIndex (> n) [1, 3 ..]
in succ i

main = mapM_ print $ [f, g] <*> [1000]</lang>
main = do
print $ f 1000
print $ g 1000</lang>
{{Out}}
{{Out}}
<pre>501
<pre>501