Merl's Blog

New Tools

This is a tale regarding the effectiveness of new tools, along with it’s growing pains, and also a battle between my humility and ambition.

In yesterday’s blog I was talking about how tools like numpy can make life easier. I have completed days 1-5 in the year 2015 of the Advent of Code calendar. I have completed a few other day 1s and 2s from other years, but I’m trying to progress as much as possible in 2015. If you are unaware, I believe that as the days progress so does the difficulty.

I thought to myself, why not try to learn a new tool like numpy while doing a harder day.#genius As you might expect it was harder than you might expect.

Growing Pains

# For the last few days I have been consistently using a variation of this functions

def fetch_test_data(path):
    file = open(path, "r")
    text = file.read()
    file.close()
    return text.split("\n")

text = list(fetch_test_data('../2015/day_6.txt'))


#I looked at the numpy library and came across these 2 would be godsends.
#So sleek, simple, and elegant.

np.loadtxt('../2015/day_6.txt')
np.genfromtxt("../2015/day_6.txt")

After much time, learning is time consuming, I found that this would not work with the data I have. See the elements in the strings I was using staggered between 4 and 5 elements. As far as I could tell np.loadtxt and np.genfromtxt needed to have a consistent size array in order to not raise an error message.

I referred to it as a downfall, but more precisely it is a growing pain in learning the limitations of your new tool.

Effectiveness

Now, I must admit I still have not completed this day. I have however mapped out what I think is an optimal strategy using numpy.

The premise of the challenge is to have a 1000x1000 grid and manipulate the information inside based on coordinates that are provided. With what I learned yesterday and this fact this felt like a perfect opportunity to learn and implement numpy. Although I am in the process of piecing together different aspects of the challenge, I believe that the manipulation of the data will be made much easier with the presence of numpy.

Numpy’s ability to change data in an array is a tool I can see being useful in the future, but especially in this challenge. grid[3:7, 3:7] = 1 This is an example of how easy it would be to change that specific section of the grid to the value 1. I can’t think of a method that would do the same thing easily.

Humility and Ambition

Of course my goal is to progress as quickly as possible, however growth is not always linear. I have been trying VERY hard the past 3 days and in that time I’ve gathered 16 stars. If I learned anything from the game Mario, then I’m on the right track.

This Day 6 has been pretty tough, along with learning more about numpy. I can definitely see progress, however I had to move to another year and complete a Day 1 in order to get some stars and make my friend Mario smile.

I am pretty sure I will finish Day 6 tomorrow. Whether I will attempt Day 7 or move to another easier challenge is yet to be seen.

Until next time,

Merl