Code puzzles are fun and you can solve it with some lines of code. The code puzzle on snowisfalling.com is a page showing snow is falling up instead down. After reading the code, sleeping two nights without time to solve it, the simple solution is easy:
init : function(law){ String.prototype.reverse=function(){return this.split("").reverse().join("");} this.law = {}; for (var k in law) { this.law[k.reverse()] = law[k]; };
But a friend asked is there a bigger improvement possible. After reading the original rules of John Conway’s game of life I generated a second Law-mapping.
law.js for game of life
generate the automata-states for the game of life.
var Law = {}; (function me(depth, name, count, cond) { if (depth==9) { Law[name] = (count in cond)?1:0; } else { me(depth+1, name+"0", count, (depth==4)?{"3":1}:cond); me(depth+1, name+"1", count+1, (depth==4)?{"3":1, "4":1}:cond); } })(0, "", 0);
my solution based on the unmodified automata.js
Just open the following snow.html.
Funny … and yes, this code puzzle has a job hiring background.

Christian Harms

Latest posts by Christian Harms (see all)
- google code jam 2013 – tic-tac-toe-Tomek solution - April 16, 2013
- Google code jam 2013 – the lawnmower - April 14, 2013
- code puzzles and permutations - April 11, 2013