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
Bear with me.
https://github.com/ednl/adventofcode/blob/main/2026/04.c

static unsigned fit(const char *pat, const unsigned len)
{
    for (unsigned m = 1; m <= len; ++m) {  // try increasing lengths
        for (unsigned i = 0; i < m; ++i) {  // check all congruent indices
            char c = 0;
            for (unsigned j = i; j < len; j += m) {
                if (pat[j] == '?' || pat[j] == c)  // don't care, or good
                    continue;
                if (c)  // previously seen colour is different
                    goto next_m;  // can't be this length
                c = pat[j];  // first colour seen at this congruent index
            }
        }
        return m;  // all good so this length works
    next_m:;
    }
    return 0;  // impossibru
}
let rec set l i v =
  if i = 0 then v :: List.tl l
  else List.hd l :: set (List.tl l) (i - 1) v

let rec patlen bc =
  let s = String.(trim (replace_all ~sub:"?" ~by:" " bc)) in
  let len = String.length s in
  if len < 2 then 1 else
  let lst = List.of_seq (String.to_seq s) in
  let rec checklen n =
    if n = len then n else
    let rec checkpat pat =
      let rec check i p l =
        match p, l with
        | _, [] -> n
        | [], l -> check 0 pat l
        | x :: p, c :: l when c = ' ' || c = x -> check (i + 1) p l
        | ' ' :: _, c :: _ -> checkpat (set pat i c)
        | _ -> checklen (n + 1)
      in check 0 pat lst
    in checkpat (List.take n lst)
  in checklen 1

let () =
  let barcodes = In_channel.input_lines stdin in
  Printf.printf "%d\n%d\n"
    List.(map patlen barcodes |> fold_left (+) 0)
    (String.concat "" barcodes |> patlen)
Photo, no description
Photo, no description
:%s/^/+1 ⟨Ctrl+M⟩{O\v(\l)%(.)*\1@!\l⟨Ctrl+[⟩
qaqqayiW:v/⟨Ctrl+R⟩0/s/ .*⟨Ctrl+M⟩
/ ⟨Ctrl+M⟩:g//norm ⟨Ctrl+A⟩⟨Ctrl+M⟩{$F)yhp;p@aq@a
{ddvGJ0@v
function solve(str)
    p = Dict(k => findall(k, str) for k in "roygbv" if findall(k, str) != [])
    isempty(p) && return 1

    for l in length(keys(p)):length(str) 
        y = vcat([v for (k, v) in Dict(k => unique(v .% l) for (k, v) in p)]...) 
        length(Set(y)) == length(y) && return l
    end
end

println(sum(solve.(readlines("data/4.txt")))) # Part 1
println(solve(*(readlines("data/4.txt")...))) # Part 2
C ← ⊙◌⍢(+1|>1/↥♭◿¤⊸/↥⬚1↯⊂∞)1
⊃(/+⊜C|C▽)⊸±-@>&fras"day4.txt"
Photo, no description
Code from https://github.com/riinupius/advent2026/blob/main/day03/foggy-forest.R
dec04 =>

  input := io.stdin.read_lines! .map (.codepoints.force)

  Sequence.first_match(f T->bool) => filter f .first

  solve(l) =>
    (1..).first_match s->
      (0..s-1) ∀ o->
        fail : flow.exception_tag is
        flow.exception fail
          .try ()->
             _ := l.indexed.flat_map ||>(i,e -> (i%s = o).as_option e)
                   .foldf "?" r,e->
                     if      e="?" || e=r then r
                     else if r="?"        then e
                     else (flow.exception fail).env.cause (error "")
          .or_outcome??

  part1 =>
    input.flat_map solve
         .sum

  part2 =>
    solve <| input.fold1 (++)

  say "$part1:$part2"
Photo, no description
Advent of Code day 4 solution screenshot
Photo, no description
Photo, no description
Desktop screenshot with 3 windows open: A terminal running my day 4 script showing its (censored) output, the Advent of Code website showing a cute festive ASCII scene, and Apple Music showing my Advent of Code playlist which begins with the album Liquid Colours by CFCF
Photo, no description
Photo, no description
# PART 2

total = ''.join(strings)

# print(total)

print(test_string(total))
Load more