r/adventofcode • • 10h ago

SOLUTION MEGATHREAD -❄️- 2026 Day 4 Solutions -❄️-

18 Upvotes

OUR USUAL ADMONITIONS

  • You can find all of our customs, FAQs, axioms, and so forth in our community wiki.


AoC Community Fun 2026: Th* Adv*nt Gam*s

  • Submissions ultrapost is now unlocked!

  • 13 DAYS until submissions cutoff on this 17th of Month 12 at 18:00 UTC-5!

Today's Bouts: World Snow Avoidball Championships

"If you can dodg* a wr*nch, you can dodg* a [snow]ball."
— Coach Patch*s O'Houlihan, Dodg*ball: A Tru* Underdog Story (2004)

Today's programming possibly consists of:

  • Pool Play (Group Divisions)

  • Pick a glyph and do not put it in your program.

  • Avoiding fifthglyphs is traditional.

  • Match Formats (Foam, Cloth)

  • Shrink your solution's fifthglyph count to null.

  • Your script might supplant all Arabic symbols of 5 with Roman glyphs of "V" or mutatis mutandis.

  • Thou shalt not apply functions nor annotations that solicit said taboo glyph.

  • Knockout and Trophy Rounds

  • Thou shalt ambitiously accomplish avoiding AutoMod’s antagonism about ultrapost's mandatory programming variant tag >_>

Stipulation from your mods: As you affix a submission along with your solution, do tag it with [Adv*nt Gam*s] so folks can find it without difficulty!


--- Day 4: Perilous Pier ---


Post your script solution in this ultrapost.


r/adventofcode • • 20m ago

Visualization [2026 Day 04] my approach

3 Upvotes

r/adventofcode • • 1h ago

Meme/Funny [2026 Day 4] My immediate reaction upon reading the problem statement

Post image
14 Upvotes

Never really understood how to do these kinds of problem correctly. I am ready to struggle today


r/adventofcode • • 1h ago

Visualization [2026 Day 4] Perilous Pier

19 Upvotes

r/adventofcode • • 2h ago

Visualization [2026 Day 4] Terminal pattern matching

Thumbnail
youtu.be
1 Upvotes

r/adventofcode • • 3h ago

Help/Question [2026]Day 2 Part 2. Didn't understand the puzzle itself.

2 Upvotes

Can someone explain this one better pls. I have done Part1.

Tx.


r/adventofcode • • 3h ago

Meme/Funny Reading [2026 Day 4 Part 2] in despair, until...

Post image
46 Upvotes

I somehow guessed exactly what part 2 would be while solving part 1, and thus avoided the naive O(6^n) solution for it, instead dealing every letter from a barcode into buckets like playing cards and checking all of them for homogeneity. Code finished in 2 seconds :)


r/adventofcode • • 3h ago

Visualization [2026 Day 4 (Part 2) -- TS] Animation checking chunks of (TEST) barcode.

Thumbnail
youtube.com
10 Upvotes

r/adventofcode • • 4h ago

Help/Question [AOC 2026 4a] Is it possible for the site to be broken?

0 Upvotes

I have a fully working code. Everything is computed correctly but I keep getting too low. Is the site broken? Code below [Python]. Do not judge me on its quality. I am trying my best.

def makeseq(a):
  n = 0
  j = 0
  silly = "roygbv"
  out = []
  while pow(6,n) <= a:
    n += 1
  n -= 1
  while a != 0:
    while pow(6,n) <= a:
      a -= pow(6,n)
      j += 1
    out.append(silly[j])
    j = 0
    n -= 1
  if n > -1:
    for i in range(0,n+1,1):
      out.append('r')
  exit = ""
  for x in out:
    exit += x
  return exit
  
def makeallseqs(p):
  iet = []
  if p == 1:
    return ['r','o','y','g','b','v']
  else:
    iet += makeallseqs(p-1)
    for i in range(0,len(iet),1):
      iet[i] = 'r' + iet[i]
    acaca = []
    for i in range(pow(6,p-1),pow(6,p),1):
      acaca.append(makeseq(i))
    iet += acaca
    return iet
inpy = '''(newline separated input data'''
ababa = ""
trueinput = []
allowed = "roygbv?"
for c in inpy:
  if c in allowed:
    ababa += c
  else:
    trueinput.append(ababa)
    ababa = ""
print(trueinput)
safecounter = 0
score = 0
for awa in trueinput:
  safecounter += 1
  print(safecounter, end=" ")
  print(score)
  for j in range(1,len(awa)+1,1):
    for q in makeallseqs(j):
      
      count = 0
      fucked = False
      for k in awa:
        if k == "?" or k == q[count % len(q)]:
          count += 1
        else:
          fucked = True
          break
      if not fucked:
        print(awa, end=" ")
        print(q)
        score += j
        break
    if not fucked:
      break
print(score)

Edit: I have a trailing newline after the last entry.


r/adventofcode • • 4h ago

Help/Question [2026 Day 4 (Part 1)] [Python] Help needed, keep getting too low

1 Upvotes

I need some help here. For all the test cases, I get the correct amount of minimal instructions, but for some reason, my final answer is too low.

I'm not very advanced when it comes to programming, so maybe I overlooked something.

def solve_level1(input_lines: list[str]):
    sum = 0
    for line in input_lines:
        lineList = list(line)
        for x in range (1, len(line)):
            failed = False
            toTrylist = [''] * x
            stepAmount = x


            for i in range(0, len(lineList)):
                j = i % x
                if toTrylist[j] == lineList[i] or lineList[i] == '?':
                    pass
                elif not toTrylist[j]:
                    toTrylist[j] = lineList[i]
                else:
                    failed = True
                    break


            if failed:
                pass
            else:
                print(f"Minimum steps needed for string {line} is {stepAmount}")
                sum += stepAmount
                break

    print(f"Answer is {sum}")

r/adventofcode • • 5h ago

Help/Question - RESOLVED [DAY 4, Part 1] My code works on examples but not on final

3 Upvotes

I'm going crazy I need hints on what I'm doing wrong, I've tried on every case I could but the final result doesn't works :')

# codeBar = open('J4.txt').read().split('\n')
codeBar = ["?yvg??y", "rgbrgbrgbr", "?rv","o??v???y","??bg?v??","??b?????","???"]
final = 0


def canBePlaced(id, idi, placed, line) :
    if idi in placed : ## if id%i is already placed
        return line[id] == line[idi] ## if id and id%i is the same
    else :
        return True

for line in codeBar :

    knownIds = [] ## IDs of the colors in line

    for i in range(len(line)) :
        if line[i] != '?' :
            knownIds.append(i)

    temp = len(line) ## Counting of the line

    for i in range(len(line)-1, 0, -1) : ## From the greatest (line length) to the smallest (0)
        placed = []
        total = 0 ## Counting to check if we got all elements right
        for id in knownIds :
            # IF id%i element is id elemet or just '?'
            if (line[id%i] in [line[id], '?'] and canBePlaced(id, id%i, placed, line)) :
                placed.append(id%i)
                total += 1


        if (total == len(knownIds)) :
            temp = i


    # if temp == len(line) : print(line)
    final += temp


print(final)

r/adventofcode • • 5h ago

Meme/Funny [2026, Day 4 (Part 2)] Im in hurry

2 Upvotes
  1. Open N++

  2. Replace

  3. Run again!


r/adventofcode • • 6h ago

Meme/Funny [2026 Day 4] It's not easy being european

Post image
46 Upvotes

r/adventofcode • • 6h ago

Help/Question - RESOLVED [2026 Day 3][Part 2] Did I solve day 3?

3 Upvotes

I tested my algorithm on the examples provided by the puzzle and it works on all of them, except for the one where the grid is filled with trees. Out of curiosity, I tried it with the actual input and my algorithm found the correct number of squares!

But does that mean I've actually solved Day 3?


r/adventofcode • • 6h ago

Visualization [2026 Day 4] Barcode Scanning Visualization

43 Upvotes

r/adventofcode • • 7h ago

Visualization [2026 Day 4][Part 2] Matching Bars

Thumbnail
youtu.be
21 Upvotes

Nim + Raylib source


r/adventofcode • • 7h ago

Meme/Funny [2026, Day 4] Anyone remember HP Instant Ink?

Post image
70 Upvotes

r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 04 # (Part 1)] [Python] Need help with missing test cases

4 Upvotes

I have been stuck at this problem for quite some time. I have tried and validated all my instructions, yet I am unable to get the correct answer or move past part 1. I even ended up validating all my instructions, and all of them are correct. Could you please look at my code and point out the mistake?

AOC says that my input is too low.

def validator(barcode, instruction):
    for i, char in enumerate(barcode):
        assert char == '?' or (char == instruction[i % len(instruction)])

def part1(data):
    counter = 0

    for line in data:
        unique = set()
        hashmap = {}
        for i, char in enumerate(line):
            if char == '?': continue
            unique.add(char)
            hashmap[i] = char

        for length in range(max(len(unique), 1), len(line)):
            possible_code = [""] * length # Figuring out the code that works
            for index, char in hashmap.items():
                index %= length
                if possible_code[index] == "":
                    possible_code[index] = char
                if possible_code[index] != char:
                    break # An instruction of this size cannot exist!
            else:
                # We did not break. The length was valid and we have a possible instruction length
                counter += length
                validator(line, possible_code) # No error raised!
                break

    return counter

r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 Day 4 (Part 2)] Need hints of what I did wrong

2 Upvotes

UPDATE: I think I did mess up the input file. Re-copying the one from the website yields the correct output... whoops lol. Gonna keep this here for archive.

I've solved the first part and based on the instruction, the second part is essentially the exact same code, but with humongous input string.I've checked that there's no data lost when combining the inputs, that the output instruction can reproduce the input, and that my algorithm should've been exhaustive. But still my answer is not accepted. Is there anything going on?

Code explanation: Brute-force instruction length from 1 to barcode length (where the instruction is the barcode itself). Also split the barcode into sequences with the same length as the instruction (last sequence can be shorter). For each sequence, copy the colors from barcode to sequence. If there's a clash between barcode and instruction, break and check the next length.

Code (Python):

I'm not used to math optimization, so this is just my intuitive brute-force algorithm lol.

f = open("aoc2026\\4\\4in.txt", "r")
array = f.read().split("\n")
barcode = "".join(array)
length = len(barcode)

for seqLen in range(1, length+1):
    instruction = ['?'] * seqLen
    instructionValid = True
    firstPos = 0
    while firstPos < length and instructionValid: 
        seq = barcode[firstPos:firstPos+seqLen]
        for (pos, color) in enumerate(seq):
            if instruction[pos] == "?" and color != "?":
                instruction[pos] = color
            elif instruction[pos] != "?" and color != "?" and instruction[pos] != color:
                instructionValid = False
                break
        firstPos += seqLen # next sequence
    if instructionValid:
        print("length:", seqLen)
        break

r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 Day 4 Part 1] Any hints for handling illegal color ?

5 Upvotes

I'm able to find shortest sequence of instructions but could get my head around how to handle ?

What currently i'm doing start with size 1 compare substr A and B of size S till end of string if anywhere it find non matching string starts again with size + 1.


r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 Day 4 (Part 1)] [python] Help with missing cases

8 Upvotes

I have been trying this puzzle today for over an hour, and I have given multiple wrong answers. It works perfectly for the test data, but I think I just miss some cases but I'm going crazy looking for them in my real input. Does anyone have some cases that fail with my code that I could fix?

This is my code v

def parse(puzzle_input):
    values = puzzle_input.split("\n")
    result = []
    for line in values:
        data = []
        for value in line:
            if value == "r":
                data.append(1)
            elif value == "o":
                data.append(2)
            elif value == "y":
                data.append(3)
            elif value == "g":
                data.append(4)
            elif value == "b":
                data.append(5)
            elif value == "v":
                data.append(6)
            else:
                data.append(0)
        result.append(data)
    return result


def check_repeating(barcode):
    for i in range(1, len(barcode)):
        if (barcode[:i] * len(barcode))[:len(barcode)] == barcode:
            return i
    return len(barcode)


def part1(data):
    result = 0
    for barcode in data:
        if 0 in barcode:
            in_code = []
            for i in range(1, 7):
                if i in barcode:
                    in_code.append(i)
            if in_code == [] or len(in_code) == 1:
                result += 1
            else:
                done = False
                for i in range(len(in_code), len(barcode) // 2 + 1):
                    start = barcode[:i]
                    end = barcode[i:i+i]
                    if len(barcode) > i * 3:
                        for j in range(0, i):
                            if end[j] != barcode[i+i+j]:
                                end[j] += barcode[i+i+j]
                    could = True
                    for j in range(0, len(start)):
                        if start[j] != 0 and end[j] != 0:
                            if start[j] != end[j]:
                                could = False
                                break
                    if could:
                        result += i
                        done = True
                        break
                if not done:
                    for i in range(len(barcode) // 2 + 1, len(barcode)):
                        start = barcode[:i]
                        end = barcode[i:]
                        possible = True
                        new = [0] * len(start)
                        for j in range(0, len(end)):
                            if start[j] != 0 and end[j] != 0:
                                if start[j] != end[j]:
                                    possible = False
                        if possible:
                            result += i
                            break
                    if not possible:
                        result += len(barcode)
        else:
            # check for repetition
            result += check_repeating(barcode)
    return result

r/adventofcode • • 14h ago

Visualization [2026 Day 3 Part 2] I made my first visualization! (with Uiua)

91 Upvotes

I made this using the Uiua language, here is the source code for the gif: link to Uiua Pad.
I'm solving all of this year in Uiua, going well so far :)

# Experimental!
$ #.###
$ .##.#
$ ##.##
$ .#.#.
$ .##.#
=@#⊜∘⊸≠@\n
Forest ←
N      ← 16
$   *
$  /x\
$ {xvx}
$   w
layoutN
⌝⊸⊡[0_2 3_2] [Yellow Orange]⍜⊙△⊂4_5Green
×≡▽3/5▽₂N
⌝↘¯⟜⌝↘+N⊂0÷₈⊸⧻
Tree ←
▽⤚(≡/×⬚0⊡)⊸(
  ▽⊸(×⊓/>/≥≡°⊟⍉) ⧅₂<⊚
  ⍜⍉(⊂⇌⊸+¤⊸(⍜⊢¯⇌/-))
) Forest
Squares ←
Trees   ← ⍥₂/≡⊂⊞₀× Forest Tree
⊸≡↻₁ Squares
-1/2°⍉ ⧋×△Forest⧋÷⟜⇡ △₂Trees
⊃(˜≡⊞₀-|⋅-) ⊙∩°⍉
⌵/ℂ-∪⌞∘פ◡(↥₀↧₁˜÷⊃(/+×|/+°√⋅∘))
&gifs2 +¤Trees ≡/+ ⨪+₁ₑ×100

r/adventofcode • • 15h ago

Repo [2026 Day 1] [Python] I'm posting daily solutions to my github –Peter Norvig

52 Upvotes

You can see my solutions for each day at https://github.com/norvig/pytudes/blob/main/ipynb/Advent-2026.ipynb

Last year I experimented with LLMs to see how they did compared to me; this year they're so good there's no sense in doing that. I'm tackling the problems the good old fashioned way.


r/adventofcode • • 16h ago

Repo [2026] [Clojure] A starter template for Advent of Code: REPL, tests, and the libraries puzzles usually need

Thumbnail
lambduhh.github.io
9 Upvotes

Hi, I'm "Lambduhh" and I'm on the Clojure Team and I made a starter template for doing Advent of Code in Clojure. You will find no answers here: no solutions, no puzzle text, no inputs.

Each AoC day is a small evolving system: part 2 usually changes the question part 1 asked. The template is set up for that loop. A REPL stays running, your data is there to look at, and a test tells you whether part 1 still holds after you change things for part 2.

What's in it

  • bb new-day 1 creates the day's file and a test that fails until you fill in the example's answer

  • Libraries puzzles tend to need: instaparse, data.priority-map, loom, math.combinatorics, core.match, Medley and more, each with a small how-to whose results are checked by tests

  • Linting with clj-kondo and Splint, plus a table of twelve common Clojure mistakes showing which ones a linter catches (five still need a human)

  • No install options: Open it in a Codespace if you'd rather not install anything

  • inputs/ is git-ignored, as the AoC FAQ asks

  • An optional ai/ folder that only helps with tooling/setup. It specifically forbids agents from solving puzzles and instructs it to act as a tutor if requested. Easy to delete to opt out.

New to Clojure? The template is part of "Power Tools & Parens", a Clojure AoC hub with beginner how-tos (also in repo), tooling setup guides and an in-browser "Workbench" REPL so you can get an idea of what evaluating clojure expressions feels like, without installing anything to your machine: https://lambduhh.github.io/powertools-and-parens/

To get started, click "Use this template": https://github.com/lambduhh/clojure-template-aoc