Winter Break and Advent of Code

This winter break I gave myself the project of becoming more proficient in standard Ruby (sans Rails). In order to do this I did a bunch of coding challenges. One of the sets of challenges I tried was an Advent calendar made up of coding puzzles.

I wanted to write up a blog post about what what I learned about Ruby from gaining all 50 advent of code stars. I did a great job of erasing all Rails from my mind this break and concentrating on my programming fundamentals and use of Ruby. This will probably hurt a lot when I return to class on Monday but it also helped to cement things I’ve learned so far and teach me new things about programming. So here are a couple of things I learned from this winter adventure.

Screen Shot 2016-01-02 at 6.14.17 PM.png

Advent of Code is a 25 day challenge leading up to December 25. It’s a fun project put together so that it’s accessible for all skill levels and can be completed in any programming language. I am definitely bookmarking AoC for when I have to learn a new programming language. I tried the first five days in R and Ruby and it helped me relearn a lot of the R I’ve slowly been pushing out of my brain. My GitHub repo of AoC can be found here. This is not the prettiest code in the world and there are definitely exercises I’m more proud of than others, but regardless of code quality it’s something I finished and I learned a lot in the process. Here are a few of the things I learned.

1. Range of CS-Related Topics

What I really liked about the layout of the challenges is that most touched on a range of topics in the development world. One challenge took advantage of parsing JSON files, something web devs would know a lot about. One talked about MD5 hashes, and another about password encryption, which relates to cybersecurity. There was a challenge that related to hardware, one for bitwise operators, and lots of interesting sorting problems. It was a fantastic array of subjects to learn about for someone who has only been programming for a little while. I learned a lot about Regular Expressions as many of the puzzles had to do with large amounts of string input. I also was able to brush up on my math for the puzzles that involved coordinates. Overall, once you have the basics of a language down, doing coding puzzles like this can really help introduce you to CS topics when you did not go to school for that. The one area where my background in economics helped me was on an optimality constraint problem where you calculate happiness of guests based on who they are sitting next to. But besides that, I was pretty lost when solving problems with “jumps” and “registers” and learned a lot in the process.

2. Every Language Has Strengths and Weaknesses

During my three weeks of working on Advent of Code, I spent a lot of time on the AoC sub-Reddit reading about how people saw the problem and looking at code in Python, Java, C#, C++, Ruby, and many many more languages. I had the most fun with people’s solutions that didn’t even use code at all, but instead used pen and paper and manual logic to solve the problem. In this process, I started to realize how lucky I was to have Ruby for some of the more Object Oriented problems (everything in Ruby is an object, EVERYTHING!) and how sad I felt on the Math problems or things like bitwise operators where other languages naturally excel. By about the 10th day I could really tell if a problem could be easily solved in Ruby right away and just see the algorithm in my head if that were the case.

3. Classes, Hashes, Arrays, oh my!

I learned a lot about the various advantages and disadvantages of data structures doing these puzzles. I generally am inclined towards using arrays and hashes, but there were many times I had to scrap my algorithm half-way through realizing that I should create my own class instead. Classes are great ways to organize related data and reuse that information later. My first reaction as a new programmer is always to go for a simple way of storing the data like an array. Working through more complex puzzles made me teach myself to use objects much more often. Instances could sometimes hold information so much more clearly than hashes could. This was the most helpful on the horrible two days at the end of the puzzles where you had to basically build an RPG in order to calculate minimums. I also quickly began to adapt using hashes much more often than arrays. The information in a hash can be unordered and pulled out without an index, but with a reasonable call like a name or identifier, which is super helpful when you have a lot of information and don’t want to remember the order. I kicked myself many times for using arrays early on and then having no idea where my data was by the end of the code. I also internalized a lot about classes and object creation in the longer puzzles.

4. Countless Amazing Ruby Things

The biggest thing I learned during the last two weeks has been all of the amazing Ruby modules, methods, gems, etc. that make doing hard stuff easy. The three biggest modules I learned advanced things about while solving the puzzles were Array, Enumerable, and Regexp. I probably know or have seen every Ruby enumerable at this point. Here are my new favorite Ruby things in no particular order:

  1. #each_cons(n): gives you arrays of n amount in consecutive order so if you called it on [1, 2, 3, 4] and wanted arrays of 2 it would give you back [1, 2], [2, 3], [3, 4]. Isn’t that grand? Great for combinations of linear items.
  2. #combination(n) and #permutation(n): Give an array and the number of elements in each array and get all combinations or permutations of that array. The difference between these two methods was hard to get used to. Basically, if order matters you want a combination and if it doesn’t, go for permutation.
  3. Class: Set:  I used sets a lot instead of array#uniq in order to push only uniq items into a data structure.
  4. Module: Benchmark: Provides methods to measure and report time used to execute the code. When I wasn’t sure if I was just being inefficient or stuck in an infinite loop, I’d use Benchmark.
  5. #each_with_index: Oh, God. What would I do without #each_with_index? This method allows you to do what each does but also keep track of the index you are at in the array.
  6. Class: Digest.hexdigest: Returns the hex-encoded hash value of a given string, helpful for the cyber security questions.
  7. #zip: takes one element from an array and merge the corresponding elements from each array, zipping them together.
  8. Rubular: a website that allows you to play around with Ruby regular expressions.
  9. Handling of bitwise operators (binary numerals at the bit level) showcased well in this article.
  10. #sub, #match, #gsub, #inspect, #take and #name_captures: all ways to handle regular expressions and find string or digit matches inside a particular string. #name_captures even returns a hash! Figuring out how to use all these correctly was a major hurdle and felt great to overcome.

There are many more awesome Ruby things I learned in this process. I also enjoyed comparing Ruby solutions with other languages. I would love to return to these one day and solve them in another language (or two!).

5. Scalability a.k.a. “THERE’S A PART TWO?!”

A great thing about AoC is that every puzzle had a second part. That second part was either easy or hard to solve, usually based on how you set up the first part. With that in mind, it was always helpful to not be hack-y in your solution to the first part. This caused me to spend more time thinking through what the puzzle was asking than brute force hacking.

6. ❤ pry & irb ❤

This post is dedicated to irb and pry. I love you. And you are my best friends in Ruby. Thank you. You will find commented out (and a few stray not-commented-out) binding.pry’s in all of my code. Debugging was key to finishing these puzzles.

Jon Stewart, Comedy, and Craft

A short thought.

So I was on a few planes this week and I had a lot of down time to read and think. I finished Andy Weir’s The Martian. It was okay. Should make for a good movie. Anyway, I got to engage in one of my favorite down-time past-times: listening to a gajillion billion podcasts. Besides NPR, The Read, Another Round, Call Your Girlfriend, Slate, etc. (all the favorites), I decided on a whim to search for “Jon Stewart” in podcasts and dug up some old interview’s he did on Fresh Air and Bill Moyer’s show. I have watched Jon Stewart for as long as I’ve been interested in politics… so for the whole tenure of his time on the Daily Show. I have always felt a strong connection to his righteous anger on issues of corruption in the media and in politics. Sad about his leaving the show, I decided to listen to him speak about comedy and his time early on in the show. In this search, I came across an interview he did with Dave Davies in 2004 that struck a chord for me. Here is an excerpt from their conversation:

DAVIES: And you decided to go to New York and do standup […] And at first just got brutalized, as people do. And I’m wondering – you know, there are lots of people who are funny, that make their friends laugh, make their families laugh […] I mean, you were so funny, you had that brain working that way. What was it you didn’t know?

STEWART: What was I didn’t know about which?

DAVIES: About why didn’t it work? Why is being funny with your friends not the same thing as…

STEWART: Well, because it’s a craft, you know? It isn’t – there’s a big difference between having an analytical mind and being a good scientist. There is a craft to learn. And that was the biggest lesson is that it takes – again, it’s that idea of turning obnoxiousness into wit or comedy. You know, creating something from nothing is different from just being reactive at a bar. And you have to create the atmospheric conditions for comedy. Comedy is oddly enough very fragile and can be thrown off by, you know, a glass breaking or somebody talking or – you, know, there’s a lot of different elements to it that – and construction of a joke – you know, you have to create – one of the things about being funny life is the premise is already there.

This completely encapsulates my motivations and thinking as I delve further into projects in programming (and as I try to defend this divergent path to friends and family as well). There are lots of people who are sharp, who are analytically minded, who are the most creatively critical in a classroom. I was one of those kids. I’m an analytical person. However, being smart or analytical is exactly like being funny around friends in Jon Stewart’s case. There is a big difference between the potential and the profession. I think that in this year after my graduation, I want to build craft. What a word. Craft. 10,000 hours. I want to work hard at something that is intellectually exhausting and come out the other side two, five, ten years down the line, with a craft. As Stewart says, the biggest thing to learn is taking that energy and potential and turning it into something, producing something, and building something, and then channeling that something positively. I see so many similarities between comedy (purely, the most intricate and nuanced facet of language itself) and code similar to how I saw similarities between linguistics and code. And that comes down to craft. Craft is not a manual. It is not something that can be taught straightforwardly. It is an expert intuition, always moving and evolving, it is nuanced in its execution. When this craft is tuned and focused and then let grow through improvisation, it can be amazingly beautiful.

Wow, I got to go code some more.

tumblr me8m1h0m161qcmnsuo1 400 All the Jon Stewart GIFs you'll need as he leaves 'The Daily Show

breathe in, code out

This week has been a jumble. I worked a lot at the place I wash dishes at the beginning of the week, and in between have not stopped staring at different things on my computer. I finished App Academy’s introductory materials and began to take their coding quizzes. I got through all ten “beginner” problems in one sitting, although it took me a while and I sure struggled. I felt so good after completing my reading but seeing

def Method
  #your code goes here!
end

really freaked me out. I took a breath in, and tried to breath out code. I was proud that I completed all the problems without looking at the answers. I mean I did Google (but only twice!) to find some techniques, but didn’t ever search out solutions. I was feeling a lot of euphoria completing the assignments and having all my tests go green. And then… I looked at the solutions. Compared to the solutions my code was a little wonky. Let’s take an example which sums a range of numbers (but you should already know that looking at the variable names I hope…):

def sum_nums(num)
  range = (0..num).to_a
  range.inject(:+)
end

and this is the solution they provided:

def sum_nums(num)
  result = 0
  i = 0
  while i <= num
    result += i
    i += 1
  end

  return result
end

Meh… that doesn’t look much like mine, does it? And I assume it’s a much better use of principles as well. I think that right now when I see or hear a problem I could solve with code, my brain fires up the “panic! what do you remember to solve this!” engine and then I tweak and tweak until the specs come up green. This probably means I just need to spend more time with the syntax and logic (esp. loops) until it becomes much more natural for my brain. When I’ve learned languages in the past (Spanish, Latin, Yorùbá, Hindi), I’ve gotten to this point in drilling the basics where I start to dream in those languages. It’s hilarious at first because the dream is really only in partial phrases and incoherent statements. That started to happen with Ruby last night. I had a dream about a method I was trying to write, but for the life of me I couldn’t tell you what it was supposed to do. It was bizarre, but hopefully it means I’m beginning to get the hang of the language. Gah, this is too much fun.

In other code updates, I just finished the first level of Ruby Monk. It’s on to Ruby Koans next for more syntax practice. Funny enough, I actually completed Ruby Koans a while ago when a Ruby dev recommended it to me. I trotted along in it because the interaction on the CLI is pretty straight-forward, but to honest it really didn’t stick. I completed a whole section on RegEx without really ever understanding what I was doing. I’m going to now go through it again with better control of some basics.

In terms of IRL coding, I just finished a Girl Develop It course in Seattle. The course was on HTML/CSS which, while not programming, was fun and an awesome opportunity to meet some community members. In the CSS part of class I kind of realized… I’m not a big fan of design. I mean, I’m a HUGE FAN of looking at awesome design by others, but I just don’t think I’m personally cut out for that. This could change, but tweaking the colors and div sizes/margins/etc. was not the most fun. Data is the most fun. But this is all evolving.

In the mean time I’ve been thinking a lot about this idea of “Write. Code. Speak.” It’s the idea that not only should you be programming or coding, but also writing and speaking about programming, tech, social issues, etc. There already so much out there to learn and keep learning that also attending Meetups every week, writing a blog, keeping up with my online newbie community, and also you know.. making a living in Seattle can be overwhelming. However, this is what I LOVE about this community and world. Unlike academic economics, what I previously thought I may do, developers actually recognize and discuss these issues. I find this especially cool/heartening this morning, with the recent SCOTUS ruling and having a Twitter community to celebrate with.

Happy Friday! I just found out that Ada Developers Academy is opening up applications for their fall class so I’ll just be over here koan-ing and trying not to freak out from joy/fear/excitement.

App Academy Prep Work!

So I am not sure that I’ll apply to App Academy, but I have a friend who is now a developer who attended their camp and is very excited about the possibility that I will also attend. So I thought I’d take a look. To be honest, I’ve been freaking out a little bit over the last day about it. It’s a pretty intimidating bootcamp. I’m absolutely up for the work and I honestly think I’d be a good fit. I have just been realizing something over the last week about myself: I like to be certain I know something before I’m tested. I once had a friend tell me the the best teachers (and thus the best communicators) are the ones that can struggle the most effectively. I love this sentiment because it’s absolutely my learning style. I like to struggle a lot before I’m teaching or communicating with others about those ideas. This is probably why I enjoy coding so much. It’s a constant struggle (i.e. you never stop learning, so cool!)

Anyway, I’ve decided to complete the App Academy prepwork and test myself on it. This may not lead to me actually applying to App Academy but will definitely lead to me being a better programmer. And it will give me the opportunity actually finish and work through an ENTIRE tutorial on Ruby for the first time (resource overloadddddddd). I will be updating this blog with my progress for the time being but in the meantime here’s the prep work:

I. Before Coding Challenge 1

II. Before Coding Challenge 2

III. Extra Optional (I’ve heard are helpful but not possible to get all the way through)

Phew, think that’s enough prep work? Well, I’m getting started today with the “Intro to Programming” and hoping to finish RubyMonk this week. I’m keeping this all organized on this site and *gasp* on paper! I’m excited to finally get a little organized and actually finish a tutorial. To be honest, I read all of Chris Pine’s book and tried the exercises every chapter but found that the way I approached the exercises I was constantly using clunky or non-descript variable names and I often leaned on the solutions. Now I want to commit myself to some memorization and muscle-memory building techniques so that the syntax and logic becomes more intuitive for me. Here goes & stayed tuned!