Monthly Archive for February, 2009

100 Switches Puzzle

At the Stanford Alumni Job Fair today, Shop It To Me has an unique way of recruiting/attracting developers.

100 lights puzzle

So here, interested developers were challenged to solve a puzzle written on the black board.

Being a fan of puzzles (and a fan of the bulb puzzle), I gave it a try.

Here’s how the puzzle goes

Assuming 100 switches for 100 lights are switched off. First, toggle every switch the 1st round. The 2nd round, toggle every 2nd switch (from the start) of 100. 3rd round, toggle every 3rd switch. This goes on until the 100th round. Which lights are turned on and why?

Being unwilling to do too much thinking mentally, I wipe out my laptop to write a simple javascript script to solve this quickly.

<!– solve_puzzle.html –>
<!– easy way of solving the 100 switches puzzle by joshua koo –>
<textarea id="console" style="width:400px; height:300px">
This is a simple way to display output
</textarea>
<script>
// Let 100 lights/switches be an array
var lights= new Array();

// All switches are turned off. Not neccessary but may initialize them as false
//for (var i=1;i<=100;i++) { lights[i] = false; }

for (var i=1;i<=100;i++) { // For 100 rounds
for (var j=i;j<=100;j+=i) { // Start with the number and incriment itself
lights[j] = !lights[j]; // Toggle the switch
}
}

// Display the result
for (var i=1;i<=100;i++) {
if (lights[i]) document.getElementById(’x').value += i + "\n";
}
</script>

So this is a programmatic solution to the puzzle. For a more mathematical + logical solution read this.

4 Things About Me

While something like writing 25 random facts about oneself seem to viral on facebook these days, I always shy away describing myself. Either I’m not honest about myself, or perhaps I like surprising others with a hidden side of the my multifacet self.

4 Things About Joshua

Instead here’s 4 short points on what I wrote about myself around 6 months ago working at iStorez. It comes with manipulated head on a baby’s body with a old school camera as seen on the blurbs @ iStorez’s Team page.

In case you’re wondering, iStorez’s a startup with a unique shopping content and its unique technology helps collect and organize deals, promotions and discounts across retailers and stores. In the past 8 months, I’ve focused on building, deploying and maintaining partner integrations solutions, such as Yahoo Deals! Storewide Sales. I’ve used js, css for the frontend, java servlets and jsps, sometimes php mid-tier layers, and in the backend there’s management of tomcat, mysql, other linux services and servers, and yup some shell + python scripts and java apps for cron jobs too.

Of course, it doesn’t end there, and at times I do some analytics, some photographing, and some times maybe, entertainment. Considering this is the first post since I’ve been here for 8 months, make a guess how occupied I’m.

Oh, coming back to myself. I’ve just left a note on my domain, (finally) on what I’m currently occupied with.

JoshuaKoo.com

Keep Going

Something I remember from a book about journals - keep writing, even in times its difficult to write. Inspiration doesn’t come always, and sometimes the motivations and goals for doing something turn dim. The book mentions a lady who was depressed after losing a loved one, didn’t have the inspiration to write about new things, but keep recording seemingly mundane actions like waking up, sleeping and eating for a long period of time, and eventually that helped her recover.

Because I started this blog initially for myself, at times, I feel apologetic to myself for not maintaining my blog. Sometimes I procrastinate when I have too many things to write about. Then times swing when I’m unsure of what to write. At least I keep a little diary where I dump my thoughts and feelings in it and 6 months after I’m here, reading them helps me measure myself.

And my photos here (or here @ facebook) these days seem to be the outlet of expressing the (almost daily) adventures I’m going through.

Have a great year of 2009 ahead, if I haven’t greeted you so, late but better than never.

2009 New Year Fireworks, San Francisco
New Year Fireworks 2009, San Francisco, from Treasure Island.