Jump to content

Hofstadter Figure-Figure sequences: Difference between revisions

→‎{{header|Haskell}}: Applied Hlint, hindent to second Haskell version
(→‎{{header|Haskell}}: Applied hlint hindent, adjusted one name to side-step Wiki formatting glitch)
(→‎{{header|Haskell}}: Applied Hlint, hindent to second Haskell version)
Line 980:
<lang haskell>import Data.List (sort)
 
r :: [Int]
r = scanl (+) 1 s
s = 2:4:tail (compliment (tail r)) where
compliment = concat.interval
interval x = zipWith (\x y -> [x+1..y-1]) x (tail x)
 
s :: [Int]
s = 2 : 4 : tail (complimentcomplement (tail r)) where
where
compliment complement = concat . interval
interval x = zipWith (\x y -> [succ x+1 .. pred y-1]) x (tail x)
 
main :: IO ()
main = do
putStr "R: "; print (take 10 r)
putStr "S: "; print (take 10 sr)
putStr "test 1000S: ";
print (take 10 s)
print ([1..1000] == sort ((take 40 r) ++ (take 960 s)))</lang>
putStr "test 1000: "
print ($ [1 .. 1000] == sort ((take 40 r) ++ (take 960 s)))</lang>
output:
<pre>
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.