Zachary Lopez

Hack Reactor - Week 2 Day 4

Another awesome day. Past 10pm again. This is starting to become a trend.

Highlights of the day:

  • More N-queens
  • Talk by Laurie Voss
  • Sushirrito

More N-queens

Today we further refined our N-queens solution. We implemented this a completely bitwise solution following an academic paper.

Here is the code:

function q(n){x=0,a=(1<<n)-1;function i(l,c,r){if(c==a)x++;var p=~(l|c|r)&a,b;for(;p;p-=b){b=p&-p;i((l|b)<<1,c|b,(r|b)>>1)}}i();return x}

You may have noticed that I tweeted this out today. That’s right, a program that can find up to 17 queens in a reasonable amount of time in 138 characters. Amazing!

After that, we pursued even more speed improvements. We first implented the solution using HTML 5 Web Workers. This worked okay, but didn’t really take advantage of having a 4 core CPU. The processes were threaded, but not running in parallel.

So we hit the web, and stumbled upon Parallel.js. This totally sweet library made it super easy to parallelize our algorithm and push the cpu to max usage of all 4 cores. Ultimately, this got us to N=19 at 48.5 mins.

Andy and I, however, were still not done. Our next path is to distribute the computing across multiple computers to bring the time down further and get our N into the 20s. We have a 1 week break after this week, and I have a feeling we will be working on this further to see how far we can get. This won’t be the last you hear of n-queens. So pumped!

Talk by Laurie Voss

Laurie Voss, the CTO of npm. He talked all about the industry, what to look for as junior devs entering the market, and various technical topics. This was an enlightening two hours that feel like a bonus round. Just great advice on approach to the mountains of things we could learn. Laurie talked about servers, caching, hiring, interviews, coding conventions, html rules, css rules, etc, etc.

HR keeps bringing the knowledge.

Sushirrito

Had one. Awesome sauce. Will again. Enough said. Good night!

comments powered by Disqus