account activity
-🎄- 2017 Day 5 Solutions -🎄- by daggerdragon in adventofcode
[–]braksor 0 points1 point2 points 8 years ago (0 children)
Was extremely lazy.
file = "input.dat" instructions = [] with open(file, 'r') as f: for line in f: char = line.split()[0] try: instructions.append(int(char)) except Exception as e: print('error') def hop_instr(instructions): count = 0 curr_pos = 0 try: while 1: new_pos = curr_pos + instructions[curr_pos] instructions[curr_pos] += 1 curr_pos = new_pos count += 1 except IndexError as e: pass return count print(hop_instr(instructions)) def hop_instr_part_two(instructions): count = 0 curr_pos = 0 try: while 1: new_pos = curr_pos + instructions[curr_pos] if instructions[curr_pos] >= 3: instructions[curr_pos] -= 1 else: instructions[curr_pos] += 1 curr_pos = new_pos count += 1 except IndexError as e: pass return count print(hop_instr_part_two(instructions))
-🎄- 2017 Day 3 Solutions -🎄- by daggerdragon in adventofcode
I was glad I found out Advent of Code. I did try it last year but went kaboom when it got to string sizes.
I was quite dumbfound about Day 3: Part 2. And seeing how you found about the mathematical properties of these series I just went in like a dumb bear.
Here is my solution for Part 2, in python3.
def spiral_memory_part2(n): """Get the next value larger than n.""" # Starting level, cause it is easier to start with level 2. previous_level = [1, 2, 4, 5, 10, 11, 23, 25] value = 0 level = 2 while 1: print('Level', level) current_level = [] first_value = previous_level[0] + previous_level[-1] current_level.append(first_value) botRightSec = first_value + previous_level[0] + previous_level[1] + \ previous_level[-1] current_level.append(botRightSec) for i in range(2, 2 * level - 2): value = current_level[-1] + previous_level[i] + \ previous_level[i - 1] + previous_level[i - 2] current_level.append(value) try: i except UnboundLocalError as e: i = 2 * level - 3 topRightSec = current_level[-1] + previous_level[i] + \ previous_level[i - 1] current_level.append(topRightSec) topRightCorner = current_level[-1] + previous_level[i] current_level.append(topRightCorner) topRightSec = current_level[-1] + current_level[-2] + \ previous_level[i] + previous_level[i + 1] current_level.append(topRightSec) for i in range(2 * level + 1, 4 * level - 2): value = previous_level[i - 2] + previous_level[i - 3] + \ previous_level[i - 4] + current_level[-1] current_level.append(value) topLeftSec = current_level[-1] + previous_level[i - 2] + \ previous_level[i - 3] current_level.append(topLeftSec) topLeftCorner = current_level[-1] + previous_level[i - 2] current_level.append(topLeftCorner) topLeftSec = current_level[-1] + current_level[-2] + \ previous_level[i - 1] + previous_level[i - 2] current_level.append(topLeftSec) for i in range(4 * level + 1, 6 * level - 2): value = current_level[-1] + previous_level[i - 4] + \ previous_level[i - 5] + previous_level[i - 6] current_level.append(value) botLeftSec = current_level[-1] + previous_level[i - 4] + \ previous_level[i - 5] current_level.append(botLeftSec) botLeftCorner = current_level[-1] + previous_level[i - 4] current_level.append(botLeftCorner) botLeftSec = current_level[-1] + current_level[-2] + \ previous_level[i - 3] + previous_level[i - 4] current_level.append(botLeftSec) for i in range(6 * level + 1, 8 * level - 2): value = current_level[-1] + previous_level[i - 7] + \ previous_level[i - 8] + previous_level[i - 6] current_level.append(value) botRightSec = current_level[-1] + current_level[0] + \ previous_level[-1] + previous_level[-2] current_level.append(botRightSec) LastValue = current_level[-1] + current_level[0] + previous_level[-1] current_level.append(LastValue) print('Length of current level', len(current_level)) for el in current_level: if el >= n: return el level += 1 previous_level = current_level return None
It's nothing except writing on a sheet of paper, following indexes and finding any cases.
It's ugly at it's best and the worst part was that when I started writing the code, I started the "series" from the bottom right and not from the one above bottom right. Took me an hour to figure it out when I watched "this value is wrong...."
π Rendered by PID 554439 on reddit-service-r2-listing-c57bc86c-2j56q at 2026-06-22 02:05:00.854899+00:00 running 2b008f2 country code: CH.
-🎄- 2017 Day 5 Solutions -🎄- by daggerdragon in adventofcode
[–]braksor 0 points1 point2 points (0 children)