Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
47
Task/Recamans-sequence/Haskell/recamans-sequence-3.hs
Normal file
47
Task/Recamans-sequence/Haskell/recamans-sequence-3.hs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import Data.List (find, findIndex, nub)
|
||||
import Data.Maybe (fromJust)
|
||||
import Data.Set (Set, fromList, insert, isSubsetOf, member)
|
||||
|
||||
--- INFINITE STREAM OF RECAMAN SERIES OF GROWING LENGTH --
|
||||
rSeries :: [[Int]]
|
||||
rSeries =
|
||||
scanl
|
||||
( \rs@(r : _) i ->
|
||||
let back = r - i
|
||||
nxt
|
||||
| 0 > back || elem back rs = r + i
|
||||
| otherwise = back
|
||||
in nxt : rs
|
||||
)
|
||||
[0]
|
||||
[1 ..]
|
||||
|
||||
----------- INFINITE STREAM OF RECAMAN-GENERATED ---------
|
||||
--------------- INTEGER SETS OF GROWING SIZE -------------
|
||||
rSets :: [(Set Int, Int)]
|
||||
rSets =
|
||||
scanl
|
||||
( \(seen, r) i ->
|
||||
let back = r - i
|
||||
nxt
|
||||
| 0 > back || member back seen = r + i
|
||||
| otherwise = back
|
||||
in (insert nxt seen, nxt)
|
||||
)
|
||||
(fromList [0], 0)
|
||||
[1 ..]
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main = do
|
||||
let setK = fromList [0 .. 1000]
|
||||
(putStrLn . unlines)
|
||||
[ "First 15 Recamans:",
|
||||
show . reverse . fromJust $ find ((15 ==) . length) rSeries,
|
||||
[],
|
||||
"First duplicated Recaman:",
|
||||
show . head . fromJust $ find ((/=) <$> length <*> (length . nub)) rSeries,
|
||||
[],
|
||||
"Length of Recaman series required to include [0..1000]:",
|
||||
show . fromJust $ findIndex (\(setR, _) -> isSubsetOf setK setR) rSets
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue