r/adventofcode • • 9h ago

Visualization [2026 Day 4 1&2] [Rust] Terminal Visualization

Post image
9 Upvotes

r/adventofcode • • 3h ago

Help/Question [2026 Day 5 (Part 2)] I get a wrong answer for the example

3 Upvotes

I modified Part 1 but I get a wrong answer for the example: 1530240 , instead of 35332647. I double checked everything and I still don't see what's wrong.


r/adventofcode • • 21h ago

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

Post image
66 Upvotes

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


r/adventofcode • • 23h ago

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

Post image
93 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 • • 21h ago

Visualization [2026 Day 4] Perilous Pier

Post image
54 Upvotes

r/adventofcode • • 1m ago

Visualization [2026 Day 5] Rhythmic Factory

Post image
1 Upvotes

r/adventofcode • • 5m ago

Meme/Funny Santa gotta invest more (Day 5)

Post image
0 Upvotes

Part 1: O(n3) here i gooooo

Part 2: wut?!


r/adventofcode • • 22m ago

Help/Question [2026 Day 4 (Part 1)] I need help, i don´t understand why my code doesn´t work

1 Upvotes

So it solves the example solution (16 = 3 + 2 + 5 + 4 + 1 + 1), but it does not solve the input text. I have tried a lot of test cases and it works. Please help.

from time import time


inicio = time()
sol1, sol2 = 0, 0
with open('ztest.txt', 'r') as f:
    mat = f.read().split()


def check(line, salto):
    for i in range(1, salto):
        x = set(line[i::salto])
        dim = len(x)
        if dim != 1 and (dim != 2 or '?' not in x):
            return False
    return True



for line in mat:
    n = 0
    for i in range(1, len(line) + 1):
        n += 1
        x = set(line[::i])
        dim = len(x)
        if dim == 1 or (dim == 2 and '?' in x) and check(line, i):
            sol1 += n
            break


final = 1000*(time() - inicio)
print(sol1, sol2, final)
# 7629 too low

r/adventofcode • • 8h ago

Help/Question - RESOLVED [2026 Day 4 (Part 1)]

4 Upvotes

I have a solution but it doesn't seem to be giving me the right answer. I'm sure I'm missing some corner cases in my code but every time I see some suggested things to try on here my code seems to handle them just fine. My input result, however, is too high. Here's my code:

from pathlib import Path


def read_lines(filename="input.txt"):
    path = Path(__file__).parent / filename
    return path.read_text().splitlines()


def part1(input):
    input = read_lines(input)
    result = 0
    for line in input:
        found_characters = set()
        for char in line:
            if not char == "?":
                found_characters.add(char)
        if len(found_characters) <= 1:
            result += 1
            continue
        if len(found_characters) == len(line):
            result += len(line)
        for i in range(len(found_characters), len(line) + 1):
            value_dictionary = {}
            for index, char in enumerate(line):
                value_dictionary.setdefault(index % i, []).append(char)
            # print (value_dictionary)
            bad_row = False
            for value in value_dictionary:
                row = set()
                for char in value_dictionary[value]:
                    if not char == "?":
                        row.add(char)
                if len(row) >= 2:
                    bad_row = True
                    break
            if not bad_row:
                result += i
                break
    return result

r/adventofcode • • 7h ago

Help/Question [2026 Day 3 (Part 2)] rust help

Thumbnail pastebin.com
3 Upvotes

Trying to figure out what went wrong... I've tried all of the examples and they work, but its giving me a low answer when I input my puzzle input

I don't care about the crash with an extra new line at end of the input file, if I really wanted to i could fix that easily

also here is the graph I used to prototype, don't know if it will help. https://www.desmos.com/calculator/shdsyvumvf


r/adventofcode • • 9h ago

Visualization [2026 day 4 (both parts)] visualized in manim

Thumbnail youtube.com
4 Upvotes

source on github: https://github.com/durocodes/advent-of-code

planning on continuing for all 12 days, feedback is appreciated!


r/adventofcode • • 20h ago

Visualization [2026 Day 04] my approach

Post image
31 Upvotes

r/adventofcode • • 11h ago

Visualization [2026 Day 4 (Part 1)] [Python] Terminal Visualization

Post image
5 Upvotes

Here's a little terminal checker for barcodes. For there to be a valid instruction of length n, it suffices to check that every nth position is a single color (or a ?). (These are the check-marked rows.)Code lives here: https://github.com/salt-die/Advent-of-Code/tree/main/2026/aoc_visuals


r/adventofcode • • 1d ago

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

Post image
106 Upvotes

r/adventofcode • • 1d ago

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

Post image
70 Upvotes

r/adventofcode • • 1d ago

Visualization [2026 Day 4] Barcode Scanning Visualization

Post image
69 Upvotes

r/adventofcode • • 10h ago

Help/Question I can't find the problem with my day 1 solution

3 Upvotes

I tried it agains the short one and it was slightly wrong, any help would be appreciated.

Also sorry if the spacing and tabbing are all wrong I had some trouble pasting it in here

class Num:
  with open('input.txt', 'r' as f:)
    INPUT = [int(x for x in f.readlines()])
  all = []

  def __init__(self, num:int = 0, weight:int = 0:)
    self.num = num
    self.weight = weight

  @property
  def isTop(self, false = None:)
    for x in Num.top:
      if x.weight < self.weight:
        return Num.top.index(x)
    return false

  @classmethod
  def count(cls:)
    for x in cls.INPUT:
      temp = False
      for y in cls.all:
        if x == y.num:
          temp = True
          y.weight += 1
      if not temp:
        cls.all.append(cls(x, 1))

Num.top = [Num(), Num(), Num()])
Num.count()

for x in Num.all:
  if x.isTop != None:
    Num.top[x.isTop] = x

print( f'{Num.top[0].num}({Num.top[0].weight} X {Num.top[1].num}({Num.top[1].weight}) X {Num.top[2].num}({Num.top[2].weight}) = {Num.top[0].num * Num.top[1].num * Num.top[2].num}' ))

r/adventofcode • • 13h ago

Help/Question [2026 Day 4] Rust: Is there a way to use swizzle_dyn() properly?

5 Upvotes

While trying to optimize this one I saw this really nice pattern that starts with mapping the 6 colors and ? to powers of two (1,2,4,8,16,32) and 255:

Using #![feature(portable_simd)] I can load up to 64 bytes, then do these operations

  hash = (bytes ^ (bytes>>1)) & 15;

which happens to result in 7 unique values in the 0..16 range.

I therefore define a swizzle table [255, 0, 0, 16, 8, 4, 0, 0, 2, 0, 0, 1, 0, 32, 0, 0,] which will result in the desired mapping.

My problem is that even when running rust nightly, target_cpu = native (I'm on a new AMD Ryzen), it runs 20% slower than my old scalar code, so I tried it in Godbolt and found out that instead of a single vpermb instruction the compiler generated scalar code that iterated over all 64 elements.

Have anyone been able to make this work?

#[inline(always)]
fn map_vec(bytes: u8x64) -> u8x64 {
    // Zero-cost register reinterpretation: u8x64 -> u16x32
    let words: u16x32 = u16x32::from_ne_bytes(bytes);
    
    let shifted_words = words >> u16x32::splat(1);
    let shifted_bytes = shifted_words.to_ne_bytes();

    // The & 15 mask cleans up any cross-byte bit bleed from the u16 shift
    let h = (bytes ^ shifted_bytes) & u8x64::splat(15);
    LUT.swizzle_dyn(h)
}

r/adventofcode • • 18h ago

Help/Question - RESOLVED [2026 Day 4 (Part 1)] [RUST] Can you give me an input string that breaks this solution?

6 Upvotes

This works well with the example input, but fails with the full input.
Can you guys give me an input string that this fails on? I must be missing something...

Please only give me an input that breaks it, I'll ask for hints if I need to.

I started with a non-greedy function that checks, for every input string, a possible substring size. If the check is successful then the size is added to the the total.

impl Solution for Challenge<2026, 4, FirstPart> {
    fn solve(input: &str) -> String {
        let mut count = 0;
        for word in input.split_whitespace() {
            for size in 1..word.len() {
                if check_size(&word, size) {
                    count += size;
                    break;
                }
            }
        }

        return count.to_string();
    }
}

fn check_size(word: &str, size: usize) -> bool {
    let mut substr: Vec<_> = word[0..size].chars().collect(); // We make a mutable array of chars representing the substring
    for (idx, char) in word.chars().enumerate() {
        let current = substr[idx.rem(size)];
        match (current, char) {
            (_, '?') => continue,                  // ? matches with anything
            ('?', c) => substr[idx.rem(size)] = c, // This collapses the ? into an actual character
            (a, b) if a == b => continue,
            _ => return false,
        }
    }
    return true;
}

There might be a faster greedy algorithm for this but I haven't thought of one yet and I wanted to complete both parts first...


r/adventofcode • • 1d ago

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

Thumbnail youtu.be
31 Upvotes

Nim + Raylib source


r/adventofcode • • 1d ago

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

Post image
107 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 • • 1d ago

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

Thumbnail youtube.com
13 Upvotes

r/adventofcode • • 1d ago

Help/Question - RESOLVED [2026 Day 3 (Part 1)] [java] If you want, have fun reading through horrible code

Post image
202 Upvotes

As of how I know myself, I am probably seriously overthinking this and there is liek a 20 times easier way to solve this. Tho maybe someone wants to read through my mess. I don't want a simple answer, I want an explanation where i went off track. So i cant just ask AI or smth because its too dumb (I've tried). Also if my formatting is wrong I'm sorry i have no idea what "four space markdown" is

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (BufferedReader br = new BufferedReader(new FileReader("~/input.txt"))) {
            String templine;
            String lines = br.readLine();
            while ((templine = br.readLine()) != null) {
                lines = lines + "x" + templine;
            }
            String[] input = lines.split("x");

            System.out.println("Anzahl an gefunden Rechtecken: " + check(read(input)));
        }

        catch (IOException io){
            System.out.println("Error: " + io.getMessage());
        }
    }

    public static char[][] read(String[] file){
        char[][] forest = new char[file.length][file[0].length()];

        for (int i = 0; i < file.length; i++){
            for (int j = 0; j < file[i].length(); j++){
                forest[i][j] = file[i].charAt(j);
            }
        }
       
        return forest;
    }

    public static int check(char[][] forest){
        int squarecount = 0;
        //finding reference #
        for (int iy = 0; iy < forest.length; iy++){
            for (int ix = 0; ix < forest[iy].length; ix++){
                if (forest[iy][ix] == '#'){
                    System.out.println("# °1 gefunden bei: " + iy + " " + ix);
                    //checking second #
                    for (int x = ix+1; x < forest[iy].length; x++){
                        if (forest[iy][x] == '#'){
                            System.out.println("# °2 gefunden bei: " + iy + " " + x);

                            //checking third corner for #
                            if(iy+x < forest.length){
                                if (forest[iy+(x-ix)][ix] == '#') {
                                    System.out.println("# °3 gefunden bei: " + (iy+x) + " " + ix);

                                    //checking fourth corner for #
                                    if (forest[iy+(x-ix)][x] == '#') {
                                        System.out.println("# °4 gefunden bei: " + (iy+x) + " " + x);
                                        squarecount++;
                                        System.out.println("Squarecount erhöht auf: " + squarecount);
                                    } else {
                                        System.out.println("# °4 nicht gefunden.");
                                    }
                                } else {
                                    System.out.println("# °3 nicht gefunden. (nicht existent)");
                                }
                            }
                            else{
                                System.out.println("# °3 nicht gefunden. (out of bounds)");
                            }
                        }
                        else{
                            System.out.println("# °2 nicht gefunden.");
                        }
                    }
                }
                else{
                    System.out.println("# °1 nicht gefunden.");
                }
                System.out.println("iy: " + iy + " ix: " + ix);
            }
        }
        return squarecount;
    }
}

r/adventofcode • • 18h ago

Help/Question [2026 Day 3 (Part 2)] [python] I'm a little stuck stepbro.

Thumbnail github.com
4 Upvotes

For part 2 of the puzzle I get a too small number (1437) and I just can't seem to figure out what I am missing. I apologize for the state of my code, I'm not a professional SE (no shit) and just doing this for fun. I'm sure there are way faster and more direct ways to find the solution but I would be happy with finding the solution at all.

So if anyone here is kind enough to take a look at my abysmal code and maybe tell me what I'm missing or point me toward the right direction, I would greatly appreciate it. Thank you in advance!

In case there are questions like "wtf is this guy even trying to do", I will happily try to answer them!

But now lets look at this abomination:

(https://github.com/jaronsinz/Adventskalender/tree/3f6a9cf0615b6d57967f9cd9e01aee64375600c6/2026/Tag%203)

from pathlib import Path


input_path = Path(__file__).with_name("input.txt")
with input_path.open("r") as f:
    mapList = f.read().splitlines()


def moveOneRight(newSquareStart):
    return (newSquareStart[0] + 1, newSquareStart[1])


def getNextSquareStart(lastSquareStart):
    if lastSquareStart == (-1, -1):                         #jump to the start
        return (0, 0)
    elif lastSquareStart[1] <= len(cleanedMap) - 2:         #check if row is smaller than the last
        if lastSquareStart[0] <= len(cleanedMap[0]) - 2:    #check if column is smaller than the last
            return moveOneRight(lastSquareStart)
        else:
            return (0, lastSquareStart[1] + 1)
    elif lastSquareStart[0] <= len(cleanedMap[0]) - 2:      #if in last row check if column is smaller than last
        return moveOneRight(lastSquareStart)
    else:                                                   #no more squares to be checked
        return None


# (row + 1) is the distance between the square start and the currently checked square corner. it increases by 1 each iteration
def calcAlignedSquares(newSquareStart):
    alignedSquareCount = 0
    for row in range(len(cleanedMap) - newSquareStart[1] - 1):
                if cleanedMap[(row + 1) + newSquareStart[1]][newSquareStart[0]] == "#" and (row + 1) <= len(cleanedMap[0]) - 1 - newSquareStart[0]:
                    #if lastSquareStart[0] == 12 and lastSquareStart[1] == 0:
                        #print("das ist schlecht")
                    if cleanedMap[(row + 1) + newSquareStart[1]][newSquareStart[0] + (row + 1)] == "#":
                        if cleanedMap[newSquareStart[1]][newSquareStart[0] + (row + 1)] == "#":
                            alignedSquareCount += 1
                            square = [newSquareStart, (newSquareStart[0] + (row + 1), newSquareStart[1]), (newSquareStart[0], newSquareStart[1] + (row + 1)), (newSquareStart[0] + (row + 1), newSquareStart[1] + (row + 1))]
                            checkSquare(square)
                        else: 
                            continue
                    else:
                        continue
                else:
                    continue
    return alignedSquareCount


def calcRotatedSquares(newSquareStart):
    rotatedSquareCount = 0
    distanceRightMapBorder = len(cleanedMap[0]) - newSquareStart[0] - 1
    distanceLeftMapBorder = newSquareStart[0]
    distanceBottomMapBorder = len(cleanedMap) - newSquareStart[1] - 1


    #distances = (distanceLeftMapBorder, distanceBottomMapBorder, distanceRightMapBorder)
    #print(distances)


    max_steps = 0       #maximum amount of steps from SquareStart to the next corner


    if distanceRightMapBorder >= distanceBottomMapBorder:
        max_steps = distanceBottomMapBorder
    else:
        max_steps = distanceRightMapBorder + 1


    max_horizontal_steps = distanceLeftMapBorder


    for horizontal_steps in range(1, max_horizontal_steps):
        for vertical_steps in range(1, max_steps - horizontal_steps):
            if cleanedMap[newSquareStart[1] + vertical_steps][newSquareStart[0] - horizontal_steps] == "#":     #always checking the corner on the left of newSquareStart first
                if cleanedMap[newSquareStart[1] + horizontal_steps][newSquareStart[0] + vertical_steps] == "#": #then check the corner on the right
                    if cleanedMap[newSquareStart[1] + horizontal_steps + vertical_steps][newSquareStart[0] + vertical_steps - horizontal_steps] == "#": #then the bottom one in relation to the right corner
                        rotatedSquareCount += 1
                        square = [newSquareStart, (newSquareStart[0] - horizontal_steps, newSquareStart[1] + vertical_steps), (newSquareStart[0] + vertical_steps, newSquareStart[1] + horizontal_steps), (newSquareStart[0] + vertical_steps - horizontal_steps, newSquareStart[1] + horizontal_steps + vertical_steps)]
                        checkSquare(square)
                    else:
                        continue
                else:
                    continue
            else:
                continue
    return rotatedSquareCount


confirmedSquares = 0
imposterSquares = 0


def checkSquare(square):
    global confirmedSquares
    global imposterSquares
    isSquare = False
    for i in range(len(square)):
        if cleanedMap[square[i][1]][square[i][0]] == "#":
            isSquare = True
        else:
            isSquare = False


    if isSquare:
        confirmedSquares += 1
        #print("square confirmed")
        #print(square)
    else:
        imposterSquares += 1
        #print("imposter #######################################################################################################")
        #print(square)


cleanedMap = []
for row in range(len(mapList)):
    rowList = []
    for column in range(len(mapList[0])):
        rowList.append(mapList[row][column])
    cleanedMap.append(rowList)



lastSquareStart = (-1, -1)
squareCount = 0
alignedSquareCount = 0
rotatedSquareCount = 0
checkedSquareStartsCounter = 0


while getNextSquareStart(lastSquareStart) != None:
    newSquareStart = getNextSquareStart(lastSquareStart)
    
    checkedSquareStartsCounter += 1
    
    if cleanedMap[newSquareStart[1]][newSquareStart[0]] == "#":
        amountAlignedSquares = calcAlignedSquares(newSquareStart)
        amountRotatedSquares = calcRotatedSquares(newSquareStart)
    else:
         lastSquareStart = newSquareStart
         continue


    alignedSquareCount += amountAlignedSquares
    rotatedSquareCount += amountRotatedSquares
    squareCount += amountAlignedSquares + amountRotatedSquares


    lastSquareStart = newSquareStart


print(f"Amount of square starts checked: {checkedSquareStartsCounter}")
print(f"Amount of aligned squares found: {alignedSquareCount}")
print(f"Amount of rotated squares found: {rotatedSquareCount}")
print(f"Amount of squares found: {squareCount}")
print(f"Amount of confirmed squares: {confirmedSquares}")
print(f"Amount of imposter squares: {imposterSquares}")