Snow is falling - code puzzle

Christian Harms's picture

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:

  1.   init : function(law){
  2.     String.prototype.reverse=function(){return this.split("").reverse().join("");}
  3.     this.law = {};
  4.     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.

  1. var Law = {};
  2.  
  3. (function me(depth, name, count, cond) {
  4.     if (depth==9) {
  5.         Law[name] = (count in cond)?1:0;
  6.     } else {
  7.         me(depth+1, name+"0", count, (depth==4)?{"3":1}:cond);
  8.         me(depth+1, name+"1", count+1, (depth==4)?{"3":1, "4":1}:cond);
  9.     }
  10. })(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.

Comments

chrismarklee's picture

Thanks for the code

Chris