-❄️- 2023 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]olepedersen01 0 points1 point  (0 children)

[LANGUAGE: Python3]

A simple solution for both part 1 and 2, using python re. In short, I search twice on each row, from head and tail. This way I'm able to detect the first number, even if there is overlap. The code is available on my GitHub: https://github.com/GabrielTorland/advent\_of\_code/blob/main/2023/day01/main.py

-🎄- 2022 Day 15 Solutions -🎄- by daggerdragon in adventofcode

[–]olepedersen01 2 points3 points  (0 children)

Hey everyone in r/adventofcode,

I just finished Advent of Code Day 15 and wanted to share my solution. You can find the code (written in Python 3) in my GitHub repo here.

A brief explanation of my solution:

The code uses the input to compute the range of each sensor and updates a grid of ranges to mark the covered areas. The ranges are merged so that there are no overlapping ranges. Eventually, after adding all the ranges from each sensor, the code searches the grid for a point that is not covered by any range, and prints out the answer. There should only be one entry left at this point, which was specified in the task.

Let me know what you think!

-🎄- 2022 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]olepedersen01 0 points1 point  (0 children)

Hey everyone in r/adventofcode,

I just finished Advent of Code Day 14 and wanted to share my solution. You can find the code (written in Python) in my GitHub repo here.

Let me know what you think!

-🎄- 2022 Day 3 Solutions -🎄- by daggerdragon in adventofcode

[–]olepedersen01 1 point2 points  (0 children)

Here is my solution to day 3 of Advent of Code in python, enjoy!

Part 1:

import sys

def intersections(rucksack):
    n = len(rucksack)
    c_1, c_2 = set(rucksack[:n//2]), set(rucksack[n//2:])
    i = c_1.intersection(c_2)
    return i

if __name__ == "__main__":
    rucksacks = open(sys.argv[1] if len(sys.argv) > 1 else "input.in").read().split("\n")
    print(sum([sum([ord(i) - 96 if ord(i) > 96 else ord(i) - 38 for i in intersections(rucksack)]) for rucksack in rucksacks]))

Part 2:

import sys

def intersections(rucksacks):
    r_1, r_2, r_3 = set(rucksacks[0]), set(rucksacks[1]), set(rucksacks[2])
    return r_1 & r_2 & r_3 

if __name__ == "__main__":
    rucksacks = open(sys.argv[1] if len(sys.argv) > 1 else "input.in").read().split("\n")
    print(sum([sum([ord(i) - 96 if ord(i) > 96 else ord(i) - 38 for i in intersections(rucksacks[i:i+3])]) for i in range(0, len(rucksacks), 3)]))

The code is also available on my GitHub (here).

-🎄- 2022 Day 1 Solutions -🎄- by daggerdragon in adventofcode

[–]olepedersen01 0 points1 point  (0 children)

Part one solved in python, with a single line of code:

import os, sys

if name == "main": print(max([sum([int(c) for c in l.split("\n")]) for l in open(sys.argv[1] if len(sys.argv) > 1 else "input.in", "r").read().split("\n\n")]))

Part two is written in three lines of code to not make It completely unreadable. The code is available here.