It's been almost 3 weeks since I began The Firehose Project core program and I feel a little better and confident about the direction that I'm headed in. Since the last time I posted, I've done a few algorithms and the three quiz assignments. The last two weeks were rough with time because of gigs, teaching, work, and coding assignments. Since I finally just completed all that, I can finally dedicate a moment to posting my progress!
The three blur algorithms I finished recently are very challenging; the last one taking me a total of four straight days to finally figure out. I started to feel overwhelmed by the second blur challenge. All I could remember was..."What the hell do I do?".
The goal behind the second blur challenge was to turn all 0s adjacent to a 1, into a 1, like this:
#This is the original image to the blurred one 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 to 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The concept of 2d arrays and the logic behind looping through them by rows(up and down) and columns(left and right) started to make more sense as I researched online and looked at previous recorded firehose office hour meetings that are held every Wednesday. The hardest part didn't come till the third blur algorithm where you needed to do a Manhattan Distance worth of blur, which is basically the calculation of distance between two points. The Manhattan Distance turned out to be the hardest due to the way I had my code set. I kept reseting any changes to the array that the loop made previously. I sat for hours just trying to figure out how to not reset the loop and that is when a fellow firehoser, whom I helped previously with the second blur challenge, contacted me on slack and asked how I was doing. After going back and forth for an hour he suggested I use another Marshal(deepcopy trick) to keep the changes; it worked!
def blur(n = 1) #n = The Manhattan Distance Variable @blurred = Marshal.load(Marshal.dump(image)) #Deepcopy trick i = 0 while i < n @image.each_with_index do |row, r_pos| row.each_with_index do |col, c_pos| #CHANGE STUFF #CHANGE MORE STUFF end end i += 1 @image = Marshal.load(Marshal.dump(@blurred)) #This stops the loop from reseting end return Image.new(@blurred) end
One of the biggest things I realized from being stuck for so long and knowing why was that; you can't underestimate yourself. From all that I've learned with The Firehose Project so far, is that I definitely, within this short time, have all the tools necessary to be successful. Regardless of knowing what to do in the current situation; you have the means to find out and understand. Sometimes the answer is right under your nose! If that takes a fresh set of eyes for you to realize, it's another story!