[Haskell-beginners] Haskell Bin Tree Cellular Automata.
Henk-Jan van Tuyl
hjgtuyl at chello.nl
Thu Jun 4 23:28:30 UTC 2015
On Fri, 05 Jun 2015 00:50:25 +0200, Sourabh <sourabh.s.joshi at gmail.com>
wrote:
> I figured out that I am constantly re-computing the trees, and decided to
> try and memoize the results. Here is my memoization attempt:
> https://github.com/cbrghostrider/Hacking/blob/master/HackerRank/FunctionalProgramming/Recursion/cellular_automata_memoize_attempt.hs
>
> Basically I have changed the simulateCellularAutomata function, which
> computed the new trees, into a list (automataTrees - line 60). I was
> expecting the results to be memoized, but the runtime is unchanged.
At a glance: maybe if you change the line
automataTrees starttree rule = (starttree) : [ simulateAutomataStep
Nothing rule ((automataTrees starttree rule) !! (n-1)) | n <- [1..]]
to
automataTrees starttree rule = iterate (simulateAutomataStep Nothing
rule) starttree
it will run faster. The function 'iterate' can be found in Prelude and
Data.List.
Regards,
Henk-Jan van Tuyl
--
Folding at home
What if you could share your unused computer power to help find a cure? In
just 5 minutes you can join the world's biggest networked computer and get
us closer sooner. Watch the video.
http://folding.stanford.edu/
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
More information about the Beginners
mailing list