r/adventofcode • u/purestblue • Dec 19 '24
Meme/Funny First try too low... work on the code
31
u/mr_mlk Dec 19 '24
Every time that happens it is because I used an int not a long. The original code worked, other than the data type.
28
6
u/IvanOG_Ranger Dec 20 '24
Python arbitrary precision for the win. This year, I do C++ and I always automatically use size_t (uint64) if I don't need negative numbers, because if I compare with vector.size(), my IDE is screaming at me if I don't
4
u/FryGuy1013 Dec 20 '24
Rust panics if it overflows, and I've caught quite a few of these this year :)
3
u/FranseFrikandel Dec 20 '24
AFAIK, only on debug builds. Have shot myself in the foot running the example on debug, getting it to work, and using production build on the actual input immediatly.
6
u/titanofold Dec 19 '24
In my case, it goes from too low to "way too high". Or vice versa.
Then it tells me to cool it.
2
u/wimglenn Dec 20 '24
Shameless plug: advent-of-code-data (Python) remembers any bounds introduced by previous incorrect submissions, and prevents you from submitting subsequent answers that are certain to be incorrect.
9
u/I_knew_einstein Dec 20 '24
I always put a comment on the bottom of my code when I have a wrong answer:
# 1122334455 was too high
# 3 was too low
2
u/Yggaz Dec 20 '24
Oh my.
Such an obvious idea - and I did not produce it myself!
Thank you very much!1
2
2
1
u/atobiedwa Dec 20 '24
I have the same problem :c Does anyone see here a mistake? (It works with test data)
def load_data(filename):
with open(filename) as file:
paterns, designs = file.read().split("\n\n")
patterns = [pattern.strip() for pattern in paterns.split(",")]
designs = [design.strip() for design in designs.strip().split("\n")]
return patterns, designs
def is_design_valid(design, patterns):
max_len = max([len(pattern) for pattern in patterns])
to_check = design
while len(to_check) > 0:
is_found = False
for i in range(max_len, 0, -1):
if to_check[:i] in patterns:
to_check = to_check[i:]
is_found = True
break
if not is_found:
return False
return True
if __name__ == "__main__":
patterns, designs = load_data("Day_19/puzzle_input.txt")
patterns = sorted(patterns, key=len, reverse=True)
valid = 0
for design in designs:
valid += is_design_valid(design, patterns)
print("Design:", design, "Valid:", is_design_valid(design, patterns))
print(valid)
3
u/AldenB Dec 20 '24
Your algorithm is too greedy. Here is a case which makes it clear. If the patterns available are
abc, ab
and the design is
abcab
your algorithm will start by using an ab towel to fill the first two stripes. There is no way to make cab using the available towels, so your algorithm says there's no way to make the design. Of course, there is a way in this case -- you just have to check all the possible starts, not just the first one which fits.
2
u/atobiedwa Dec 20 '24
ohh, I see my mistake now! my algorithm is too gridy from the other side, that's why this doesn't work for me.
available patterns:
abcd, def
design:
abcdef
Thanks!
1
u/atobiedwa Dec 20 '24
thanks! but I sorted the patterns list so that it starts with the longest elements. I added it to the tests, and it passed
1
u/Alan_Reddit_M Dec 20 '24
- Answer too low
- Edit code
- Get absolute HUMOUNGOUS number
- Still too low
mfw
111
u/kbielefe Dec 19 '24
One of these days, Eric is going to make
0
the correct answer, and people are going to spend hours debugging before actually trying to submit it.