r/adventofcode • • 2d ago

Help/Question 2026 - day 1 part 1, Python

Post image

where am I going wrong? I tried plugging in the example set of numbers and it gave me the right numbers but it isn't giving me the right numbers with the main set of numbers. I'm a beginner when it comes to coding, my only experience with apcsp and apcsa in school

0 Upvotes

17 comments sorted by

12

u/flwyd 2d ago edited 2d ago

What happens if one == 20, sec == 15, and third == 10 with the_count == 25?

2

u/johnpeters42 2d ago

Or rather one == 20, two == 15, and three == 10

2

u/flwyd 2d ago

Thanks, fixed. I was typing around my cat :-)

8

u/inadequate-gravitas 2d ago edited 2d ago

Try with these inputs:

1
2
2
3
3
3

What would you expect for the result, and how does that compare to the actual result? Can you trace through one item at a time and figure out what you’re missing?

0

u/AutoModerator 2d ago

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


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

2

u/AutoModerator 2d 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/Apprehensive-Cow257 2d ago

for my input, it gave the right answer (checked with my answer), maybe a problem with the multiplication? idk

3

u/RazarTuk 2d ago

No, there really is a major flaw with the code. Your input's just... ordered correctly for it to still work. If you want to figure out why, the set 1 2 2 3 3 3 (in that order) will illustrate it

0

u/hobbes244 2d ago

A list is not the best approach. Counting the numbers in the list is O(n) and because you’re doing it for every item, you’re suddenly quadratic. Find a way to iterate over the list one time and then determine the most frequent items.

0

u/WangChud 2d ago

Look at collections, it helped me out with this one.

2

u/8dot30662386292pow2 2d ago

dict is right there without using collections.

1

u/WangChud 1d ago

Explain.

1

u/8dot30662386292pow2 1d ago

     x = {}

1

u/WangChud 1d ago edited 1d ago

That's a dict alright. Now show how it applies to the problem.

2

u/8dot30662386292pow2 1d ago

Counter is just fancy way of doing this trivial algorithm:

for number in input.splitlines():
   if number in x:  
      x[number] = x[number]+1
   else:
      x[number] = 1

The rest is them easy, because you can just take the items, sort by the value and you have the largest.

Given the apparent level of OP (novice) it's better to use the basics, instead of from solutions import wholesolutionforday1

You're not wrong though! Collections is very good knowledge for a python programmer.

1

u/WangChud 1d ago

That makes sense. Perhaps I will work 2 solutions for the advent problems, one with a 'helper module' and one that's sheer logic. Thanks for the detailed response, I'm enjoying AoC ;)

1

u/8dot30662386292pow2 1d ago

I was also roasted some years ago using a ready made polygon class for something.

Everyone can set their own constraints after all. The standard library of the selected language defines what you can easily do, and then you can also decide if you allow external libraries.

If someone worked with C, they would have to build their own hashmap (dictionary) from scratch for example.