<div dir="ltr">Wow, it runs in 0.44 seconds now. This is incredible! Can you explain what just happened here?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 4, 2015 at 4:28 PM, Henk-Jan van Tuyl <span dir="ltr"><<a href="mailto:hjgtuyl@chello.nl" target="_blank">hjgtuyl@chello.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, 05 Jun 2015 00:50:25 +0200, Sourabh <<a href="mailto:sourabh.s.joshi@gmail.com" target="_blank">sourabh.s.joshi@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I figured out that I am constantly re-computing the trees, and decided to<br>
try and memoize the results. Here is my memoization attempt:<br>
<a href="https://github.com/cbrghostrider/Hacking/blob/master/HackerRank/FunctionalProgramming/Recursion/cellular_automata_memoize_attempt.hs" target="_blank">https://github.com/cbrghostrider/Hacking/blob/master/HackerRank/FunctionalProgramming/Recursion/cellular_automata_memoize_attempt.hs</a><br>
<br>
Basically I have changed the simulateCellularAutomata function, which<br>
computed the new trees, into a list (automataTrees - line 60). I was<br>
expecting the results to be memoized, but the runtime is unchanged.<br>
</blockquote>
<br></span>
At a glance: maybe if you change the line<br>
automataTrees starttree rule = (starttree) : [ simulateAutomataStep Nothing rule ((automataTrees starttree rule) !! (n-1)) | n <- [1..]]<br>
to<br>
automataTrees starttree rule = iterate (simulateAutomataStep Nothing rule) starttree<br>
it will run faster. The function 'iterate' can be found in Prelude and Data.List.<br>
<br>
Regards,<br>
Henk-Jan van Tuyl<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
-- <br>
Folding@home<br>
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.<br>
<a href="http://folding.stanford.edu/" target="_blank">http://folding.stanford.edu/</a><br>
<br>
<br>
<a href="http://Van.Tuyl.eu/" target="_blank">http://Van.Tuyl.eu/</a><br>
<a href="http://members.chello.nl/hjgtuyl/tourdemonad.html" target="_blank">http://members.chello.nl/hjgtuyl/tourdemonad.html</a><br>
Haskell programming<br>
--<br>
</font></span></blockquote></div><br></div>