advent of code day 1

In [72]:
# code below
# below that is words about the codes
# spoilers without context to follow
# i warned u
In [15]:
from numpy import loadtxt
lines = loadtxt("puzl_1_input.txt", delimiter="\n")
[  137.   138.   139. ... 10180. 10182. 10194.]
In [28]:
inc_count = {'inc' : 0, 'dec' : 0}
a = lines[0]
a
Out[28]:
137.0
In [29]:
for i in lines[1:]:
    if i < a:
        inc_count['dec'] += 1

    else:
        inc_count['inc'] += 1
    a = i
inc_count
Out[29]:
{'inc': 1711, 'dec': 288}
In [31]:
2000 - inc_count['dec']
Out[31]:
1712
In [71]:
line_list = list(lines)
new_list = []
for i in line_list:
    i = int(i)
    new_list.append(i)
    
new_list[:10]
Out[71]:
[137, 138, 139, 140, 143, 146, 147, 149, 155, 156]
In [51]:
sliding_container = [0,0,0]

len(new_list)
Out[51]:
2000
In [53]:
test_list = new_list[:100]
len(test_list)
Out[53]:
100
In [65]:
test_final = []

for i in range(0, len(test_list) - 1):
    if i >= len(test_list) - 2:
        print('breaking')
        break
    else:
        test_final.append(test_list[i] + test_list[i+1] + test_list[i+2])
        
len(test_final)
breaking
Out[65]:
98
In [68]:
sliding_totals = []
for i in range(0, len(new_list) - 1):
    if i >= len(new_list) - 2:
        break
    else:
        sliding_totals.append(new_list[i] + new_list[i+1] + new_list[i+2])
        
        
sliding_totals[:10]
sliding_totals[-10:]
Out[68]:
[30380, 30386, 30380, 30386, 30392, 30410, 30455, 30498, 30541, 30556]
In [67]:
137+138+139
# validating
Out[67]:
414
In [69]:
y = sliding_totals[0]
inc_count_dict = {'inc':0,'dec':0,'no change':0}
for i in sliding_totals[1:]:
    if i == y:
        inc_count_dict['no change'] += 1
    elif i < y:
        inc_count_dict['dec'] += 1
    else:
        inc_count_dict['inc'] += 1
    y = i
    

inc_count_dict
        
Out[69]:
{'inc': 1743, 'dec': 237, 'no change': 17}
In [70]:
!date
Wed 01 Dec 2021 11:50:27 PM EST

I figured out the first one!

Why am I so excited? Thanks for asking first and caring second, you're such a sweetheart internet citizen!

The Advent of Code challenges are supposed to be challenging. It is said that the first challenge (the format of the challenge is that there are two daily, solving the first opens the second) should be simple enough that one should be able to kind of, conceptualize their way through it in their head (assuming you have some computational problem solving experience under your belt or behind your ears, or between your toes - however the saying goes). The second one is the challenging one.

I was pretty excited on figuring out the first one, simply because it has been awhile since I've done any coding challenge type related activities. When I got to the second one I was admittedly dispirited. It seemed like something I've never solved before. I did think about giving up right away and then thought about asking my group how to go about working on this but then I just tried it. I did my best to break down the problem into separate tasks and even took a super long break from it to come back and actually get it on what essentially was my first try through it.

I'm not going to go the length of explaining my solution - I'm simply here to brag (mainly because I thought I was going to have a lot more trouble).

Just kidding however I do believe the remaining challenges will only get more.....

challenging

I've said the word challenge so much in this post. I'm going to overdo it in the next few lines.

Anyway, it felt good. I'm glad I took a whack at it. I totally recommend trying it or recommend to try challenging type things out there for those who don't dig programming challenges.

I am going to attempt to write a little blurb and provide some of my code daily with these challenges - I'm not sure for what purpose, as if the challenge isn't challenging enough.

K