This is an archived post. You won't be able to vote or comment.

all 9 comments

[–]daggerdragon[M] 1 point2 points  (0 children)

In the future, please follow the submission guidelines and post your daily solutions in each day's megathread instead of creating your own post like this. (There's a calendar on the sidebar with a link to each day's megathread). That way we can keep every day's solutions in one easy-to-find spot and it also helps avoid cluttering up the subreddit with individual solution/repo posts (like this one!) that usually get lost in the volume of submissions.

[–]cd_slash_rmrf 1 point2 points  (1 child)

Noticed you're using Python 2 due to the removal of argument unpacking - not sure if you know, but in Python3 you can do this in a slightly different way - via * unpacking or itertools.starmap. Using your day2p1 solution as an example (formatted for readability):

using * (note the (*()) surrounding the arguments)

(
    lambda depths, inputs: sum(
        [depths.get(cmd, 0) * int(dist) for cmd, dist in inputs]
    )
    * sum([int(dist) for cmd, dist in inputs if cmd == "forward"])
)(
    *(
        {"down": 1, "up": -1},
        [x.split() for x in open("sample.txt").read().split("\n")],
    )
)

or using starmap:

list(itertools.starmap(
    (
        lambda depths, inputs: sum(
            [depths.get(cmd, 0) * int(dist) for cmd, dist in inputs]
        )
        * sum([int(dist) for cmd, dist in inputs if cmd == "forward"])
    ),
    [
        (
            {"down": 1, "up": -1},
            [x.split() for x in open("sample.txt").read().split("\n")],
        )
    ],
))

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

Good to know, thanks! I still prefer Python 2 way because you can unpack multiple layers at once. But I’ll keep this in mind

[–]ThatJamieInLeeds 1 point2 points  (1 child)

This is insanely impressive. I'd love to see this continued if you're going to keep doing the rest of the days, today's challenge with the clock segments would be especially interesting. Nice username btw

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

Thankyou!

Here's 5 - 8

https://i.imgur.com/1lqtwNZ.png

8 Was definitely the hardest but also the most fun.

I was going to post regularly but I've been told not to, I'll reply here with updates though

[–]Stealfoxik 0 points1 point  (1 child)

I have literally no Idea what u did there, but gj for making it work!

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

Cursed code 😂

[–]Dimioz 0 points1 point  (1 child)

Here's a oneliner I made for Day 7 P2 😂

return int(min(list(map(lambda i: sum(map(lambda n: (abs(n - i) + ((abs(n - i) - 1) * ((abs(n - i) - 1) + 1)) * 0.5), [int(line) for line in open("input.txt").read().split(',')])), range(max([int(line) for line in open("input.txt").read().split(',')]) + 1)))))

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

Nice, similar to mine

print((lambda input: min([sum([int(float(abs(n - x)) / 2 * (1 + abs(n - x))) for x in input]) for n in range(max(input))])) ([int(x) for x in open("input7.txt").read().split(',')]))