Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Recamans-sequence/Haskell/recamans-sequence-1.hs
Normal file
16
Task/Recamans-sequence/Haskell/recamans-sequence-1.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
recaman :: Int -> [Int]
|
||||
recaman n = fst <$> reverse (go n)
|
||||
where
|
||||
go 0 = []
|
||||
go 1 = [(0, 1)]
|
||||
go x =
|
||||
let xs@((r, i):_) = go (pred x)
|
||||
back = r - i
|
||||
in ( if 0 < back && not (any ((back ==) . fst) xs)
|
||||
then back
|
||||
else r + i
|
||||
, succ i) :
|
||||
xs
|
||||
|
||||
main :: IO ()
|
||||
main = print $ recaman 15
|
||||
Loading…
Add table
Add a link
Reference in a new issue