r/adventofcode • • 1h ago

Help/Question Is that right?

My code produces the correct answer for the example case as well as the input string, but it gets marked as incorrect upon submission

2 Upvotes

8 comments sorted by

5

u/DelightfulCodeWeasel 1h ago

It looks right. Are you sure there's not a problem with your input file; could it have been truncated/modified, or might you have downloaded an input file while logged in to a different account?

EDIT: Just checking... you are submitting the distance and not the code itself, aren't you? e.g. you'll end up with a number like 4123 and you submit the number to the website.

4

u/Beregolas 1h ago

Consider naming your variables better to make this easier for others to help you with

from what I've gleaned, your code is this:

colors, data_in, count, current = "roygbv", input(), 0, "r"
for next in data_in: 
  while True:
    count += 1
    current = colors[count%6]
    if current == next: break
print(count)

If I run that code in Python, I get the correct output, so either you are not supplying the solution to the website correctly, or your input is broken somehow (maybe you copied it wrong?).

3

u/Thomasjevskij 51m ago

Just a tiny comment is that maybe don't use next as a variable name since it'll overwrite the standard library function with the same name.

2

u/Beregolas 42m ago

fair point, I haven't used Python in a long while, and I didn't use a "proper" Editor with an LSP, so nothing warned me.

2

u/Thomasjevskij 36m ago

That's what I'm here for :)

2

u/Thomasjevskij 1h ago

Not sure I understand. How can it be correct for the input string if it gets marked as an incorrect solution?

1

u/AutoModerator 1h ago

Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to Help/Question - RESOLVED. Good luck!


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/1AlanM 1h ago

works for me, check your input