gSchool -- Week One

Written by Dominic V. Smith.

One week almost down… 23 and some change to go.

So this week was mainly about refreshing what we learned during the pre-course work. In the span of four days, we’ve pretty much covered everything I learned on my own in the last couple of months. By this time next week, I’m pretty sure I will be in completely unchartered waters.

Class work has mainly been on the foundations of Javascript. Control flow, functions, and general good habits of work flow. All pretty standard stuff that you could probably find in the beginning of any course. For the most part, we’ve been following the flow of Eloquent Javascript

So far, what has really set gSchool’s curriculum apart for me has been the interview prep exercises and questions we’ve had. In order to be a professional developer, you need to be hired. And in order to be hired, you need to do well in an interview. Because of that, at least once a day we’ve had to work through or learn a concept that we might see in an interview. The one’s that I have enjoyed so far are the locker toggle puzzle, and learning how to convert numbers in to binary.

The locker toggle puzzle goes like this: You are standing in a school hallway lined with 100 closed lockers. You then open all 100 lockers. After this, you then close every 2nd locker (so the 2nd, 4th, 6th…98th and 100th are all closed). Then, you go to every third locker and open it if it is closed or close it if it is open (lets call this toggling the locker for our discussion). You proceed to toggle every nth locker on pass number n. So, for example, on pass number 16 – you will toggle every 16th locker. After your hundredth pass of the hallway, in which you toggle only locker number 100, how many lockers are now open? In a hall with x lockers, how many lockers remain open after pass number x?

I did not get the answer on my own, but you can check out Programmer Interview for an awesome walk-through.

As for the binary, it helped to think of binary as a base 2 number system, where the number system we are most familiar with is a base 10. In base 10, 351= 300 + 50 + 1. The breakdown of these numbers goes back to elementary school, calling the 1 in the one’s place, 50 in the ten’s place, and 300 in the hundreds place, and so on.

To convert to binary, instead of a factor of 10, we use a factor of 2 (2^0, 2^1, 2^2, 2^3, etc.). It helped me, for smaller number conversions, to create a little cheat sheet:

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256

Then if we take a number like 351, we see that 256 can go in to 351 once. So we give the 2^8 spot the value of 1, and that leaves us with a remainder of 95. 128 doesn’t fit in 95, so the 2^7 position gets a value of 0. 64 does fit, so 2^6 gets a value of 1, with a remainder of 31. 32 is too big (gets a 0 value), but 16 fits, leaving a remainder of 15. 8 fits in to 15, leaving a remainder of 7. The last three numbers fit in to each other, leaving our last three positions all with a value of one. The means that in binary, 351 = 101011111. The rough diagram below should show that.

   1    0    1    0    1    1    1    1    1
  _      _     _     _     _    _    _    _    _
256 128   64   32   16    8    4    2    1

351 = 101011111

As far as actual Javascript goes, I have one snippet I’d like to share. The problem kicked my butt for a while, but mainly because doing it in JS Bin required a commented out section of code that I kept forgetting. Once I realized it was my attention to detail, and not my code, that was tripping me up it turned out to be pretty fun.

We had to Create a ‘Guessing Game’. The game starts by picking a random number. It then prompts the user to guess the number. If the user’s number is lower/higher, it will prompt the user to enter another guess and tell the user if the guess was too high or too low. This continues until the correct guess is entered. When the correct guess is entered the user is given a success message with the correct number. Below is my solution, and hopefully a working guessing game. You should be able to hit the run button in the upper right hand corner to play the game. If you’re on a mobile device, the embeded window below might stall the page load.

JS Bin



Lastly, the people I’ve gotten to know so far at the program have been pretty amazing. There is a real eclectic mix of people. There’s another vet, a winery owner, a former Broadway performer, a fashion website owner, a restauranteur, a bunch of musicians, a former start-up CFO, and everything else in-between. But more than that, they all seem like genuinely thoughtful and passionate people.

There is also a surprising amount of diversity in our class. Of the 24 students in the class, 12 are women. We also have a wide range of ages in our class, and pretty decent ethnic diversity.

One of my new buddies candidly snapped a picture of me jamming through some coding exercises. I’ll share the pic for my friends and family, and anyone else who wants to put a face to a name.

Until next time.

Written by : Dominic V. Smith

Done At: Apr 30,2015
Categories: