Unable to load image

Advent of Code 2022 : Day 9

grate filter edition

:#marseycapyhacker:

17
Jump in the discussion.

No email address required.

Having some issues with part 1, it passes the test input but not the real one. Might not be able to finish this one.

import math

headCords = [0, 0]

tailCords = [0, 0]

tailSet = set()

tailSet.add("0 0")

R = 'R'

L = 'L'

D = 'D'

U = 'U'

def getDistance():

    return math.sqrt((headCords[0] - tailCords[0]) * (headCords[0] - tailCords[0]) + (headCords[1] - tailCords[1]) * (headCords[1] - tailCords[1]))

with open('input', 'r') as f:

    for line in f:

        dir, num = line.strip().split(' ')

        num = int(num)

        if dir is R:

            # print(R)

            headCords[0] += num

        elif dir is L:

            # print(L)

            headCords[0] -= num

        elif dir is U:

            # print(U)

            headCords[1] += num

        elif dir is D:

            # print(D)

            headCords[1] -= num

        else:

            never = 'This should never happen'

            now = 'It happened'

            assert(never is now)

        # print(getDistance())

        while getDistance() > 1.45:

            if headCords[0] is tailCords[0]:

                if headCords[1] > tailCords[1]:

                    tailCords[1] += 1

                else:

                    tailCords[1] -= 1

            elif headCords[1] is tailCords[1]:

                if headCords[0] > tailCords[0]:

                    tailCords[0] += 1

                else:

                    tailCords[0] -= 1

            else:

                if headCords[0] > tailCords[0]:

                    tailCords[0] += 1

                else:

                    tailCords[0] -= 1

                if headCords[1] > tailCords[1]:

                    tailCords[1] += 1

                else:

                    tailCords[1] -= 1

            if str(tailCords[0]) + ' ' + str(tailCords[1]) not in tailSet:

                tailSet.add(str(tailCords[0]) + ' ' + str(tailCords[1]))

# print('Final Tailset', tailSet)

print(len(tailSet))
Jump in the discussion.

No email address required.

Upmarseyd to compensate longpostbot

I might know what's wrong with it : you seem to move the head all the way first, that's not how you should do it||. Did the same mistake at first. Also, ||diagonals.

Jump in the discussion.

No email address required.

@Jinglevann just noticed what's happening with the multiple spoilers on the top post? It looks fine in preview but not in the post

you seem to move the head all the way first, that's not how you should do it||. Did the same mistake at first. Also, ||diagonals.

![](/images/16706362256072032.webp)

Jump in the discussion.

No email address required.

spoilers are disabled when there's a codeblock in the comment

Jump in the discussion.

No email address required.

That's not the problem, there are no code blocks on my post.

There are two spoilers in the post, but instead of treating them separately like it does in preview, it just takes the first and last || and makes it all a spoiler, ignoring the fact they're separate.

If you click on the spoiler you can see the end of the first spoiler and the start of the second, which are both ignored.

Jump in the discussion.

No email address required.

fixed king, sry

Jump in the discussion.

No email address required.

:#chadthankskingcapy:

Jump in the discussion.

No email address required.

Thanks, I didn't notice I'd screwed up the if/else stuff. I changed it to this and everything's golden for part 1

        else:

            if headCords[0] > tailCords[0]:

                tailCords[0] += 1

            elif headCords[0] < tailCords[0]:

                tailCords[0] -= 1

            if headCords[1] > tailCords[1]:

                tailCords[1] += 1

            elif headCords[1] < tailCords[1]:

                tailCords[1] -= 1
Jump in the discussion.

No email address required.

R = 'R'

L = 'L'

D = 'D'

U = 'U'

bruh

Jump in the discussion.

No email address required.

:marseyhacker:

Jump in the discussion.

No email address required.

you're fricking bananas if you think I'm reading all that, take my downmarsey and shut up idiot

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.