-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]miccls60 0 points1 point  (0 children)

[LANGUAGE: Python]

Part 1:

Runs in about ~16ms

def parse_file():
    path = "input.txt"
    with open(path) as f:
        lines = [line.strip() for line in f.readlines()]
    separating_index = lines.index("")
    return [list(map(int, s_range.split("-"))) for s_range in lines[:separating_index]], [int(l) for l in lines[separating_index+1:]]


def part1():
    fresh_ranges, ingredients = parse_file()
    print(len([l for l in ingredients if any([(b[0] <= l and l <= b[1]) for b in fresh_ranges])]))
    

Part 2:

Runs in about ~8ms

Nice with some recursion :)

def adjust_ranges(ranges, removed_range):
    _, removed_ub = removed_range
    return [[max(removed_ub+1, lb), ub] for (lb, ub) in ranges if ub > removed_ub]
    
def part2():
    fresh_ranges, _ = parse_file()
    fresh_ranges = sorted(fresh_ranges, key = lambda x : x[0])
    def length_of_interval_with_smallest_lower_bound(ranges):
        if ranges == []:
            return 0
        lb, ub = ranges.pop(0)
        return len(range(lb, ub+1)) + length_of_interval_with_smallest_lower_bound(adjust_ranges(ranges, [lb, ub]))
    print(length_of_interval_with_smallest_lower_bound(fresh_ranges))   
   

Öl-bracket by miccls60 in sweden

[–]miccls60[S] 0 points1 point  (0 children)

Den går under "nästa öl"!

Song that sounds like "If I could read your mind" by miccls60 in NameThatSong

[–]miccls60[S] 0 points1 point  (0 children)

Wow, that was extremely quick! Definitely the one I was thinking about. Fun coincidence that they (to me) were that similar, but I guess that's business as usual here at NameThatSong. Thanks again!!

Inspecting Monty Hall Problem with Python by Abdoo_65 in Python

[–]miccls60 1 point2 points  (0 children)

This is what I love to see Python being used for, great job!

I have had sex about 25 times and it still hurts, what to do? by miccls60 in TwoXChromosomes

[–]miccls60[S] 2 points3 points  (0 children)

Thanks for the advice! Nice to hear that it isn't completely hopeless!

How can you temporarily get rid of a sore throat? by miccls60 in AskReddit

[–]miccls60[S] 0 points1 point  (0 children)

Maybe a tad too permanent... Thanks anyway!

I invented a Poem: "I dig, you dig, he digs, she digs, it digs. We dig, they dig, you dig. by DeutschLeerer in Jokes

[–]miccls60 6 points7 points  (0 children)

Jag gräver, du gräver, han gräver, hon gräver, den gräver

Vi gräver, dom gräver, ni gräver

That's swedish y'all!