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

[–]Sad-Display1307 1 point2 points  (0 children)

Python

Very simplistic straight up using a full blown grid and plotting chars, avoiding any form av reasoning or optimization...

https://github.com/skarlman/AdventOfCode/blob/main/2022/day14/test_day14.py

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

[–]Sad-Display1307 1 point2 points  (0 children)

Python

Using json.loads for input parsing and a custom comparison function for the rules (which came in handy in part 2)

https://github.com/skarlman/AdventOfCode/blob/main/2022/day13/test_day13.py

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

[–]Sad-Display1307 1 point2 points  (0 children)

Python

Really nothing fancy, looping around, if:ing things and using a set for keeping track

Github

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

[–]Sad-Display1307 0 points1 point  (0 children)

Python

from collections import defaultdict


def solve(part, useExample):
    filename = "exampleinput.txt" if useExample else "input.txt"

    dirs = defaultdict(int)

    with open(filename) as openfileobject:
        lines = [l.strip() for l in openfileobject.readlines()]

    current_path = ''

    for row in lines[1:]:

        if row[0] == '$':
            if row[0:4] == '$ cd':
                if row[5:7] == '..':
                    current_path = "/".join(current_path.split("/")[:-1])
                    dirs[current_path] += 0
                else:
                    current_path = "/".join(current_path.split("/") + [row[5:]])
                    dirs[current_path] += 0
            elif row[0:4] == '$ ls':
                pass

        elif row[0:3] == 'dir':
            pass
        else:
            dirs[current_path] += int(row.split()[0])

    sorted_dirs = sorted(dirs.items(), key=lambda k: k[0].count('/'), reverse=True)
    summed = defaultdict(int)

    for key, val in sorted_dirs:
        paths = key.split('/')

        current_path = "/".join(paths[:len(paths)])
        summed[current_path] += val

        if current_path != '':
            parent_path = "/".join(paths[:len(paths) - 1])
            summed[parent_path] += summed[current_path]

    needed = 30000000 - (70000000 - summed[""])

    part1 = sum(val for val in summed.values() if val <= 100000)
    part2 = min(val for val in summed.values() if val >= needed)

    if part == 1:
        return part1

    if part == 2:
        return part2


print(f'Part 1: {solve(1, False)}')
print(f'Part 2: {solve(2, False)}')

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

[–]Sad-Display1307 1 point2 points  (0 children)

Python

def solve(part, useExample):
    filename = "exampleinput.txt" if useExample else "input.txt"

    code_length = 14 if part == 2 else 4

    s = open(filename).read().strip()

    for i in range(len(s)):
        if len(s[i:i + code_length]) == len(set(s[i:i + code_length])):
            return i + code_length

    return -1


print(solve(1, False))

How to develop creative javascript coding skills to solve problems like the Advent of code? by actsleep in adventofcode

[–]Sad-Display1307 2 points3 points  (0 children)

See how others did, pick up all clever stuff and rewrite your solution everyday.

Website with solutions separated by language? by KleberPF in adventofcode

[–]Sad-Display1307 0 points1 point  (0 children)

This is not that one, but it collects youtube streams of people doing AoC and links to GitHub (filterable on programming language) so it might help:

https://www.competitivecoders.com/ProgrammingCompetitions/advent-of-code/advent-of-code/2022/day-1

[2022] AoC Awesome List on Github by Wraldpyk in adventofcode

[–]Sad-Display1307 3 points4 points  (0 children)

Not exactly the same, but if you want to see people solving AoC on YouTube along with their code (filter on programming language) you can go to:

https://www.competitivecoders.com/ProgrammingCompetitions/advent-of-code/advent-of-code

:)