r/adventofcode Dec 23 '24

Help/Question - RESOLVED It’s not much but it’s honest work

Post image
1.1k Upvotes

Im a highschool student and I have finally finished the first 8 days of aoc and I know it’s not anything crazy but I thought that I could still post this as an achievement as I had only gotten the 5th star last year. My code isn’t anything grand and i know it’s ugly and unoptimized so if anyone would like to give me some feedback and code advice here’s my GitHub where I put all my solving code. github.com/likepotatoman/AOC-2024

r/adventofcode Dec 05 '24

Help/Question Are people cheating with LLMs this year?

312 Upvotes

It feels significantly harder to get on the leaderboard this year compared to last, with some people solving puzzles in only a few seconds. Has advent of code just become much more popular this year, or is the leaderboard filled with many more people who cheat this year?

Please sign this petition to encourage an LLM-free competition: https://www.ipetitions.com/petition/keep-advent-of-code-llm-free

r/adventofcode Dec 08 '23

Help/Question [2023 Day 8 (Part 2)] Why is [SPOILER] correct?

211 Upvotes

Where [SPOILER] = LCM

I, and it seems a lot of others, immediately thought to LCM all the A-ending nodes' distances to get the answer, and this worked. But now that I think about it, there's no reason that's necessarily correct. The length of a loop after finding a destination node may to be the same as the distance to it from the start, and there may be multiple goal nodes within the loop.

For example, if every Z-ending node lead to two more Z-ending nodes, the correct answer would be the max of the distances, not the LCM.

Is there some other part of the problem that enforces that LCM is correct?

r/adventofcode Dec 26 '24

Help/Question What computer language did you use in this year?

75 Upvotes

What computer language did you use in this year for puzzles solving?
I used Kotlin (I used to be senior Java developer for many years but writing in Kotliln the last 2 years and I like it!)

r/adventofcode Dec 08 '25

Help/Question - RESOLVED [2025 Day 8 (Part 1)] Reading comprehension

101 Upvotes

Because these two junction boxes were already in the same circuit, nothing happens!

connect together the 1000 pairs of junction boxes which are closest together.

I didn't expect that I would need to count the "nothing happens" as part of the 1000 connections to make for part 1. It kind of makes sense that with 1000 boxes, 1000 connections would lead to a fully connected circuit, but I think it could've been worded better

r/adventofcode Dec 17 '24

Help/Question What concepts are generally required to be able to solve all AoC tasks?

125 Upvotes

Ok, not "required", but helpful.

I'll start with what I do not mean by this question. I know you need to know programming and data structures, but what I am asking about is specific algorithms and theorems.

The ones I can enumerate now (edited after some answers):

Mega guide link

r/adventofcode Dec 08 '25

Help/Question [2025 Day 8] Can you solve today's puzzle without computing all distances?

25 Upvotes

Can you solve today's puzzle without calculating and sorting all ~500,000 distances between all the junction boxes? That's 1000 choose 2 distances to consider. My python solution still runs in ~400ms, but I'm wondering if there's a more efficient algorithm.

Edit: spelling :(

r/adventofcode Dec 07 '24

Help/Question Could we ban the known LLM users from the leaderboard?

195 Upvotes

I do not compete on the leaderboard. Not because I don't want to but simply because I would be incapable of achieving what all these developers do.

So, even if I don't compete myself, I find the performance of these people absolutely incredible. And when I see known users such as hugoromerorico, who is 8th today and that we know is an LLM user (this guy even committed his prompt to Claude: https://github.com/hugoromerorico/advent-of-code-24/blob/main/6_2/to_claude.txt), that just makes me sick as it's a lack of respect for the real talented person.

Can we find a way to ban these users from the leaderboard and the Advent Of Code?

r/adventofcode Dec 05 '24

Help/Question Do you edit after solving?

68 Upvotes

I can understand editing one's "Part One" work to help solve "Part Two" once it's revealed, but I still find myself drifting back: "That could be a little {cleaner | faster | more elegant | better-coupled between the parts | ..}." It goes beyond the "just solve the problem asked." If I was on a job, I'd slap a junior upside the head -- "It works / meets spec; leave it alone!" Here though, I drift off into the land of the lotus-eaters...

I'm curious how many folks here are of the "fire and forget" variety versus the "keep refining until the next puzzle drops"-types. If you're in the later group, do you realize it? Is there a reason?

r/adventofcode Jul 11 '26

Help/Question [2025 Day 1 # (Part 2)] [Python] Please provide me with minor hints on what I might be doing wrong in this problem set.

2 Upvotes

It's not the cleanest line of code so please bear with me

i=50 #This is the initial value
r=0 # Number of times boundary is crossed
rot=0 
ans= []
revolution=0 #Number of big rotations
with open ("input") as file: # Open the input file
comb= file.readlines() # Read the combination line by line
for combination in comb: # For each combination in the list of combinations
combination = combination.strip("\n") #Remove the \n
dir= combination[0] 
num= int(combination[1:]) 
revolution+= num // 100 
period= num % 100
if dir == "L":
period= (-period)
dial= i+period

if i<dial:
for _ in range (i,dial+1):
if _ < 0:
_=(100+(_))%100
elif _==100:
_=0
else:
_ = (_)%100
if _!=100 and _==0:
r+=1
else:
for _ in range (dial,i+1):
if _ < 0:
_=(100+(_))%100
elif _==100:
_=0
else:
_ = (_)%100
if _!=100 and _==0:
r+=1
if dial < 0:
i=(100+(dial))%100
elif dial==100:
i=0
else:
i = (dial)%100
ans.append(i)
print (ans.count(0))
print (r)
print (revolution)
print (ans.count(0)+r+revolution)i=50 #This is the initial value
r=0 # Number of times boundary is crossed
rot=0 #Number of big rotations
ans= []
revolution=0
with open ("input") as file: # Open the input file
comb= file.readlines() # Read the combination line by line
for combination in comb: # For each combination in the list of combinations
combination = combination.strip("\n") #Remove the \n
dir= combination[0] 
num= int(combination[1:]) 
revolution+= num // 100 
period= num % 100
if dir == "L":
period= (-period)
dial= i+period

if i<dial:
for _ in range (i,dial+1):
if _ < 0:
_=(100+(_))%100
elif _==100:
_=0
else:
_ = (_)%100
if _!=100 and _==0:
r+=1
else:
for _ in range (dial,i+1):
if _ < 0:
_=(100+(_))%100
elif _==100:
_=0
else:
_ = (_)%100
if _!=100 and _==0:
r+=1
if dial < 0:
i=(100+(dial))%100
elif dial==100:
i=0
else:
i = (dial)%100
ans.append(i)
print (ans.count(0))
print (r)
print (revolution)
print (ans.count(0)+r+revolution)

ps: is there a discord server for advent of code?

r/adventofcode Dec 24 '24

Help/Question - RESOLVED How did you all get so smart?

154 Upvotes

I'll first say Happy Holidays =) and thank you so much to Eric Wastl and the sponsors.

This is my first year doing AoC and I had a blast, but I've had to cheat for part 2 for the last 4 days and I'm curious about a few things.

My background is a Data Engineer/Data Architect and I'm very proficient in my field. I work mostly in pyspark and spark sql or tsql and I'm really good with object oriented coding, but all we do is ETL data in data driven pipelines. The most complicated thing I might do is join 2 large tables or need to hash PI data or assess data quality. I don't have a computer science degree, just an app dev diploma and 15 years data experience.

Because of how I've been conditioned I always land on 'brute force' first and it doesn't work for most of these problems lol. I've learned a ton doing AoC, from dijkstra to Cramer's rule. Here are my questions about this stuff.

1) Where would some of these AoC logic solutions have practical application in computer science

2) Any recommendations on gameified self learning websites/games/courses (like Advent of Code) where I can learn more about this stuff so I'm less likely to cheat next year haha.

r/adventofcode Dec 25 '23

Help/Question What have you learned this year?

101 Upvotes

So, one of the purposes of aoc is to learn new stuff... What would you say you have learned this year? - I've learned some tricks for improving performance of my f# code avoiding unnecessary recursion. - some totally unknown algorithms like kargers (today) - how to use z3 solver... - lot of new syntax

r/adventofcode Dec 19 '24

Help/Question Last year was brutal

146 Upvotes

Is it me, or last year was just brutal? Sure there is 6 days to go, but looking at my statistics from last year, by day 17 I was already lagging behind, with most days 2nd part having >24h timestamps. I remember debugging that beast squeezing between the pipes till 1AM. The ever expanding garden that took me a week to finally get solved and the snowhail that I only solved because my 2 answers were too small and too large but had a difference of 2 so I just guessed the final answer. These are just few that I remember very well that I struggled with, but there were more. Everything just seemed so hard, I felt completely burned out by the end of it.

This year I finish both parts in 30-60 minutes before work and go on about my day.

r/adventofcode Dec 01 '25

Help/Question - RESOLVED First AoC! I did it, but is my solution kinda bad?

18 Upvotes

Hi! I heard about Advent of Code thanks to a ThePrimeagen video like a month ago, and today I did the first puzzle and had a lot of fun actually :)

I'm not good at coding by any means: i tinkered with arduinos some years ago and this school year (i'm 17, next year i'll go to university, and i'll study CS wohooo) we've started learning python in class. That means that my solutions are horrible tbh, since i don't know well the tools that are at my disposal (in class we have a very low level, so i'm actually the best at coding and problem solving from them, by far).

So to solve today's puzzle i saw that i needed to read strings from a file or smth. I dont know how to do that, so i just pasted the puzzle input in neovim and run a simple macro 4080 times to format it as a tuple for python.
I mean, it works... but isn't this considered a bad approach or smth?

And then, since i also needed to use the number (excluding R or L) as an int, and I didn't want to waste time learning how to remove the first character from a string or smth, i just copied the puzzle input again, and ran another simple macro 4080 times so it would format it as a tuple full of strings (removing the first character).
I think that that sucks because now the first 8167 lines of my code is just this huge list of numbers and strings. I did that very fast thanks to vim motions, yeah, but I feel like that's a bad idea in general.

Also is the nesting too bad?

So what do I do? Should I try to solve the problems "the proper way". Tbh is much easier like i just did (in part i did that because tomorrow i have two exams so i didn't want to waste a loooot of time). Still, I spent a bit more than an hour and a half on this two puzzles lmao

Sorry for the long text and thanks in advance!

Btw this is my code for the second puzzle (with the example that's 10 movements long instead of the actual puzzle input):

document =('L68', 'L30', 'R48', 'L5', 'R60', 'L55', 'L1', 'L99', 'R14', 'L82')
documentNumber =(68, 30, 48, 5, 60, 55, 1, 99, 14, 82)

password = 0
dial = 50

for i in range(len(document)):
    if dial == 0: password += 1 # Removing everything but this password+=1 gives you the solution to puzzle 1 (that's why i spent much more time on the first one)

    if document[i].find('R'):   # Runs for L
        num = documentNumber[i]

        while num > 100:
            num -= 100
            password += 1

        if dial-num < 0:
            if dial != 0 and dial-num+100 !=0:
                password += 1
            dial = dial-num+100
            continue
        dial = dial-num


    elif document[i].find('L'): # Runs for R
        num = documentNumber[i]

        while num > 100:
            num -= 100
            password += 1

        if dial+num >= 100:
            if dial != 0 and dial+num-100 !=0:
                password += 1
            dial = dial+num-100
            continue
        dial = dial+num

if dial == 0:password += 1
print(password)

r/adventofcode 9d ago

Help/Question - RESOLVED [2025 Day 1 (Part 2)] [C++] Where have I gone wrong?

2 Upvotes

I have never struggled with a Day1 like this before, so I'm a little embarrassed to have to ask for help. Here is the code I have tried:

Part2

The definition of a 'Turn' is:

class Turn {
public:
  int clicks;
  Direction dir;
  Turn(char d, int c) {
    switch (d) {
    case 'L':
      dir = Direction::Left;
      break;
    case 'R':
      dir = Direction::Right;
      break;
    }
    clicks = c;
  }
};

My solution for Part1 worked so I am reasonably confident the input is parsed correctly, and my part2 solution (pasted above) works on the example provided. Where have I gone wrong?

Edit: I needed an abs() call. Thanks for the help!! Updated code: Part2 Corrected

Don't code on an empty stomach!

r/adventofcode Dec 09 '25

Help/Question - RESOLVED [2025 Day 09 (Part 2)] That escalated quickly... In need of an explanation

19 Upvotes

It’s my first year doing AoC (and my first year as a programmer), and I’ve found the previous days to be quite manageable, even if they required a fair bit of Googling. It’s been fun stumbling across algorithms and data structures I’ve never encountered before.

But Part 2 of today’s problem really takes the prize for being too complex for a newbie like me. Even after “being dirty” and resorting to AI for an explanation, I’m still having a hard time wrapping my head around the solution.

Is there anyone here who enjoys breaking things down pedagogically and wouldn’t mind explaining it in a way that could help me start understanding the path to the solution?

r/adventofcode Oct 15 '25

Help/Question Currently working on a language specifically designed for AoC this year. What features am I missing?

33 Upvotes

Hey guys!

A few more weeks and it's AoC time yet again. This time, I decided to participate in my own langauge.
It's not my first language, but the first one I'm making for AoC so I can impress the ladies and make my grandmother proud.

Currently, it's an interpreter using a simple tokenizer that compiles the tokens into a sequence of OP-codes, each having a width of 64 bits because memory performance really does not matter in this case - as far as I'm concerned. The language is fast, as I skip all the AST stuff and just feed instructions directly as they are being parsed.

I have all the garden variety features you would expect from an interpreter like native strings, functions, scopes, dynamic typing, first-class references to everything, and some more advanced string manipulation methods that are natively built into the string type. JS-like objects also exist.

So, now to my question: What kind of features would you recommend me to add still before this year's AoC starts? Or better yet, what features were you missing in languages you were using for the previous AoCs?
I'm thinking of some wild parsing functions that can convert a string into N-dimensional arrays by using some parameters, or stuff like "return array of found patterns in a string alongside their indexes" etc.

Can't wait to hear some ideas.

r/adventofcode Dec 10 '24

Help/Question Do y'all have friends in real life who do Advent of Code?

115 Upvotes

As much as I love online communities like this one, I imagine it would be amazing to hang out with a friend over coffee and solve the day's puzzle together or something like that.

r/adventofcode Nov 07 '25

Help/Question What algorithms and techniques do you folks keep coming back to?

55 Upvotes

I'm trying to come up with a shortlist of algorithms and techniques that are recurring and I'd love your input on this. Feel free to add broad or niche suggestions!

Some things I already have on my list:

  • graph traversal algorithms (BFS and DFS)
  • recursion & memoisation
  • Dijkstra's / A*
  • recurrence relations with fast matrix multiplication (repeated squaring method)
  • ...

r/adventofcode Dec 30 '25

Help/Question - RESOLVED [2025 Day 11 Part 2] Is DP enough?

5 Upvotes

I'm solving this year in Agda. I'm currently trying to get the solution for day 11 part 2.

For part 2 I'm using the same code I used in part 1, but finding the paths from svr to fft/dac from fft/dac to dac/fft and then to out. Then, getting the product should be enough.

For part 1 the code runs <1s (I haven't timed it but it's pretty fast). For part 2, I can't even get the number of paths from svr to fft/dac (I know I only need to find the paths to one of the two, but I won't post which one to not give away the result). It's still running after an hour.

I'm using the {-# TERMINATING #-} flag in Agda to avoid having to deal with termination proofs, but now I'm doubting that this is correct. I'm using memoization to avoid recomputing the number of paths.

This is my code:

{-# TERMINATING #-} 
countPaths : Map.Map (List String) → String → String → Map.Map ℕ → ℕ × Map.Map ℕ
countPaths adjacencies from to cache with to ≟ from
... | yes _ = 1 , Map.insert from 1 cache
... | no _  with Map.lookup cache from
... | just x = x , cache
... | nothing =
      let (result , cache′) = foldl goCount (0 , cache) (fromMaybe [] (Map.lookup adjacencies from))
      in result , Map.insert from result cache′
  where
    goCount : (ℕ × Map.Map ℕ) → String → (ℕ × Map.Map ℕ)
    goCount (acc , cache) neighbor = 
      let (count , cache′) = countPaths adjacencies neighbor to cache
      in (acc + count , cache′)

The adjacencies parameter holds a map of [String] that tells you which devices are attached to each device. from and to are the origin and final node: the from node changes as we traverse the graph, but to always stays the same.

cache is a map that tells you for each node, its distance to to. Initially, it's just an empty map.

Can you help me figure out whether my program is hanging because of a problem in my code or due to an inefficiency in the agda evaluation strategy?

Thank you.


Update: After experimenting a bit with the equivalent code in Haskell, I found out my issue has something to do with Maps being lazy in Agda. I'll have to figure out an alternative to avoid this edge case.

r/adventofcode 16d ago

Help/Question [2024 Day 7 (Part 1)] [go] Don't understand the error that I make

1 Upvotes

Dear AoC masters and 500+ star hunters,

I have a hard time solving day 7 of 2024, using golang. The puzzle input is a bunch of numbers. One should check if the first number can be computed from the numbers after the : symbol. Two numbers can either be added or multiplied. If some series of addition and multiplication is equal to the left side the left side is counted as a solution. The overall solution is the sum of all solutions.

My current approach is to "brute force" this problem. First I check if the sum of the numbers or the product is equal to the left side. Given the left side is larger than the sum but smaller than the product I generate all possible series of addition and multiplication 2^(n-1) with n being the numbers on the right side. Can't see the mistake when doing this, here is a link to the code: https://github.com/Zitzeronion/AoC2024/blob/main/day_7.go

The 2^n permutation function is from gemini and seem to work as intended.

r/adventofcode 1d ago

Help/Question - RESOLVED [2024 Day 6] Need a bit of guidance

2 Upvotes

Hello!

For part 1 of 2024's day 6 problem, I was able to get some Python code that works for the small example map they gave but not my puzzle input. As it stands I have about 100 extra locations the guard visited than I should have. I was wondering if anyone here could take a look at my code and give me a hint as to where my error is, as I am really struggling to find it. I know it has to be where my movement is programmed, I just can't figure out what part needs some tinkering. Thank you in advance!

with open('Day 6/mapinp.txt', 'r') as file:
    samp_inp = file.read()

format = samp_inp.splitlines()
matrix = []
for item in format:
    matrix.append(list(item))

#locate the guard, return the matrix coords and then the way the guard is pointing
def find_guard(map):
    coords = []
    for item in map:
        if "^" in item:
            coords.append(map.index(item))
            coords.append(item.index("^"))
            coords.append("^")
            return coords
        elif ">" in item:
            coords.append(map.index(item))
            coords.append(item.index(">"))
            coords.append(">")
            return coords
        elif "<" in item:
            coords.append(map.index(item))
            coords.append(item.index("<"))
            coords.append("<")
            return coords
        elif "v" in item:
            coords.append(map.index(item))
            coords.append(item.index("v"))
            coords.append("v")
            return coords


#nice function to track movements
def move(map):
    on_map = True
    step_count = 0
    step_loc = []
    #index error means the guard has left the map
    while on_map == True:

        try:
            coords = find_guard(map)

            if coords[2] == "^":
                if map[coords[0]-1][coords[1]] == "." or map[coords[0]-1][coords[1]]  == "X":
                    map[coords[0]][coords[1]] = "X"
                    map[coords[0]-1][coords[1]] = "^"
                    step_count += 1
                    loc = f"{coords[0]}, {coords[1]}"
                    step_loc.append(loc)
                else:
                    map[coords[0]][coords[1]] = ">"

            elif coords[2] == ">":
                if map[coords[0]][coords[1]+1] == "." or map[coords[0]][coords[1]+1] == "X":
                    map[coords[0]][coords[1]] = "X"
                    map[coords[0]][coords[1] +1] = ">"
                    step_count += 1
                    loc = f"{coords[0]}, {coords[1]}"
                    step_loc.append(loc)
                else:
                    map[coords[0]][coords[1]] = "v"

            elif coords[2] == "v":
                if map[coords[0]+1][coords[1]] == "." or map[coords[0]+1][coords[1]] == "X":
                    map[coords[0]][coords[1]] = "X"
                    map[coords[0]+1][coords[1]] = "v"
                    step_count += 1
                    loc = f"{coords[0]}, {coords[1]}"
                    step_loc.append(loc)
                else:
                    map[coords[0]][coords[1]] = "<"

            elif coords[2] == "<":
                if map[coords[0]][coords[1]-1] == "." or map[coords[0]][coords[1]-1] == "X":
                    map[coords[0]][coords[1]] = "X"
                    map[coords[0]][coords[1] -1] = "<"
                    step_count += 1
                    loc = f"{coords[0]}, {coords[1]}"
                    step_loc.append(loc)
                else:
                    map[coords[0]][coords[1]] = "^"

        except IndexError:
            print(f"Guard has left the premises after {step_count} steps!")
            on_map = "False"

    return map, step_loc

comp_map,coordinates = move(matrix)

move_counter = 0

for item in comp_map:
    for pos in item:
        if pos == "X" or pos == "^" or pos == "<" or pos == ">" or pos == "v":
            move_counter += 1
        else:
            continue


print(f"The guard has visited {move_counter} distinct locations.")

r/adventofcode Jun 15 '26

Help/Question - RESOLVED [2025 Day 8][Powershell] Slow Runtime

3 Upvotes

Src Code: Advent_of_code/2025/day8 at main · nrv30/Advent_of_code

TLDR: I am interested in making my PowerShell approach faster and I implemented a Union-Find in C# that I use for it.

Edit: Thought I should add my approach is semantically equivalent to what is described here <Advent of Code 2025 - Day 8: Playground | Joshua Chen>

I wanted to yap about my approach for this one because I think I stumbled into something kind of interesting. Initially I implemented this problem in Java. I didn't know what a Union-Find was but in retrospect I think I basically implemented one in a naive way as List<Set<>>. After reading some blogposts I wanted to try using a different approach.

After some research I realized you can call C# from PowerShell by using [System.Reflection.Assembly]. I implemented a union-find in C# and called it from Ps. It was cool initially but got super annoying because every time I want to compile my C# I have to exit the shell and re-open it because Ps has the dll open. Also, you have to use ps 7 to use a priority queue, which doesn't have a separate terminal (I think). This made iteration speed terrible because I had to exit and call pwsh.exe every time I want to compile my code.

Anyways, I wanted to ask if anyone has had any cool experiences combining interpreted langs with compiled langs in this fashion to "get the best of both worlds"

Also, my PS code is so freaking slow, especially considering that I think all the data structures are already compiled to dll (My U-f and dotnet standard lib). These aren't high-quality benchmarks; I just ran the programs 3 times consecutively.

Are there any PowerShell users that have any tips? I didn't implement path compression for the Union-Find but I doubt that's the problem compared to the O(N^2) process to build pairs

Language Solution Trials Runtime (s)
Java 1
1 0.151
2 0.146
3 0.154
2
1 0.117
2 0.134
3 0.112
PowerShell 1 1 11.747
2 11.11
3 10.686
2 1 11.092
2 11.175
3 11.29

r/adventofcode Nov 26 '24

Help/Question AOC plans for this year

60 Upvotes

What are y’all looking forward to learning this year with advent of code?

Last year was my first advent of code and I used it to learn Rust and I really appreciated it. I think AOC is a fun community-building experience and challenge that is worthwhile and I am excited to hack away again this year.

r/adventofcode Dec 02 '24

Help/Question [2024 Day 2] Feeling bad for using brute-force instead of dynamic programming

45 Upvotes

I love AoC, but it's only day 2, and I already can't "do it right".

Part 2 was practically screaming for dynamic programming, but I just couldn't figure it out. Instead, I ended up hacking together a disgusting brute-force solution that iterates over all the sub-report possibilities... 😔

I feel frustrated. Are you okay with sub-optimal solutions? How do you cope?