Zachary Lopez

Hack Reactor - Week 4 Day 4

Late night tonight, but oh so much fun.

Spent most of the day working on extra credit as my pair, Shin Uesugi, finished the basic requirements yesterday.

Highlights of the day:

Promises, promises, promises

Promises is a way to more cleanly handle asynchronous data in Javascript. This replicates the callback model, but allows you to avoid callback hell by implementing chaining and error handling. It makes a lot of sense to use it, but today we had to implement it.

Hack Reactor - Week 4 Day 3

Highlights of the day:

Node

I really like Node and the server process in general. It just makes a ton of sense to me and it is very satisfying to see info from the server reaching the client. I am starting to think I am more of a back end guy. We will see as we have databases and the like coming up soon.

Hack Reactor - Week 4 Day 2

Chatterbox

Woot! A super basic chat app built in 4 days!

See more here: Chatterbox

Hack Reactor - Week 4 Day 1

And just like that we are a quarter of the way through Hack Reactor. I’ve already learned so much and it’s showing no signs of slowing down.

Highlights of the day:

nQueens further explained

A few weeks back I posted (and tweeted) the following:

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}

In this post, I am going to expand the shortened code and explain what’s happening.

As a refresher, you can see here for the wiki on nQueens.

Here we go, first let’s start by adding some line breaks where they make sense. The code was all in one line as line breaks cost characters and would prevent it from being tweetable.

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
}