Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In the case of the JS solution, it runs horribly and is highly inefficient.[0]

For non-hot code, it is perfectly fine, but in this case, inside of a main loop like this it is a waste of cpu cyles. Compare the amount of forests here:

   $ node orig-magicForest.js 117 155 106
   total forests: 1522899
   { goats: 0, wolves: 0, lions: 223 }
   total time: 816ms

   $ node new-magicForest.js 117 155 106
   total forests: 428
   { goats: 0, wolves: 0, lions: 223 }
   total time: 6ms
[0] https://gist.github.com/chapel/1c038b2bf64b3037aaea


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: