Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
Photo, no description
Compiler output from MSBuild showing compile time took almost 13 seconds.
Photo, no description
library(tidyverse)

# A period k is feasible if and only if every modulo-k residue class
# contains at most one distinct known colour (ignoring '?').
min_period <- function(barcode) {
  chars <- strsplit(barcode, "")[[1]]
  n <- length(chars)
  # Try candidate instruction lengths from shortest to longest.
  # The first valid must be the minimum.
  for (k in seq_len(n)) {
    # Assume k works until we discover a contradiction.
    valid <- TRUE
    
    # For a repeating instruction sequence of length k, positions
    # sharing the same remainder modulo k are produced by the same
    # instruction and therefore must contain the same colour.
    for (r in seq_len(k)) {
      # Extract all barcode positions belonging to this modulo class.
      idx <- seq(r, n, by = k)
      # Unknown colours ('?') place no restrictions on the solution,
      # so only retain colours that are actually known.
      vals <- chars[idx]
      vals <- vals[vals != "?"]
      # If a modulo class contains two different known colours,
      # this value of k cannot work because one instruction position
      # would need to print multiple colours.
      if (length(unique(vals)) > 1) {
        valid <- FALSE
        break
      }
    }
    # Since periods are tested from smallest to largest, the first
    # valid period encountered is the minimum instruction count.
    if (valid) {
      return(k)
    }
  }
  # Defensive fallback. In practice k = n must always be valid.
  n
}
#part 1
barcodes <- readLines("input.txt")
answer <-
  tibble(barcode = barcodes) |>
  mutate(min_instructions = map_int(barcode, min_period)) |>
  summarise(total = sum(min_instructions)) 
answer$total
# part 2 collapse the input
barall <- paste(barcodes, collapse = "")
min_period(barall)
A screenshot of my times for Day 1-4 of Advent of Code 2026.

Day 4
00:27:03 / 00:29:12

Day 3
00:05:51 / 00:30:13

Day 2
00:07:22 / 00:16:51


Day 1
23:15:13 / 23:16:56
Photo, no description
Photo, no description
Photo, no description
Can't see the forest
Photo, no description
May contain graphic violence
The ravings of a madman
Photo, no description
all grid aligned squares in the forest
Advent of code Reddit screenshot:
[2026 Day 3 (Part 2)] I'm not proud of what I did
Mr Toad meme: It is with great pleasure to inform you that
my part 2 solution delivers a correct answer in O(N^4) time
/↧⊸△=@#⊜∘⊸≠@\n &fras "day3.txt"
≡+¤0_1⊚⊞≤⊸⇌⇡-1
⊙⊙¤=0⊸≡⊢
F ← ×⊸⬚0↻
⊙≡(/+♭F⊙F×1_¯1⊸⇌)
∩/+⊸×
parse_grid(input) = permutedims(hcat(split.(input, "")...))
mat = parse_grid(readlines("data/3.txt"))

global p1 = 0
global p2 = 0

for i in 1:size(mat, 2)
    for j in 1:size(mat, 1)
        if mat[i, j] == "#"

            for l in i:size(mat, 2)
                for k in (j+1):size(mat, 1)
                    if k - j + l <= size(mat, 2) &&
                        j - (l-i) > 0 &&
                        mat[l,k] == "#" &&
                        mat[i + (k-j) + (l-i), j - (l-i) + (k-j)] == "#" &&
                        mat[i + (k-j), j - (l-i)] == "#"
                            i == l && global p1 = p1 + 1
                            global p2 = p2 + 1
                    end
                end
            end

        end
    end
end

println(p1)
println(p2)
Photo, no description
dec03 =>

  input := io.stdin.read_lines! .map (.codepoints.map ="#" .force) .force
  w => input.count
  a := array2 w w y,x->input[y][x]
  i(y,x) => 0 <= y < w && 0 <= x < w && input[y][x]

  part1 =>
    a.index_pairs.filter ||>i
                 .sum ||>y,x->
                    (1 .. w-1-max y x).count s->
                      (i y   x+s &&
                       i y+s x   &&
                       i y+s x+s    )

  part2 =>
    a.index_pairs.filter ||>i
                 .sum ||>y,x->
                    (1 .. w-1).sum s->
                                (0..(s-1)).count r->
                                  (i y+r   x+s-r   &&
                                   i y+s-r x-r     &&
                                   i y+s   x+s-2*r    )

  Sequence.sum(f T -> N : numeric) => map f .sum

  say "$part1:$part2"
Load more