Rust
Blunt force grid navigation https://gitlab.com/landreville/advent-of-code-2024/-/blob/main/src/bin/04.rs
Blunt force grid navigation https://gitlab.com/landreville/advent-of-code-2024/-/blob/main/src/bin/04.rs
For Part One I used a depth-first search which took too long for part two. Part Two I created an adjacency list of the junction points while keeping track of the distance to the adjacent nodes at the same time. Then depth-first search through the adjacency list.
deleted by creator
Memories of Day 8. It took me too long to realize I forgot to remove the 1000 iteration limit for part two.
Took me way too long to realize I could simply add jokers to the count of the most common card in the hand.
Ruby
I decided to rotate the entire input character-by-character, then parse the numbers (see the full source here)
grid = input.lines.map(&:chomp).map {|l| l.each_char.map.to_a }.to_a transposed = Array.new(grid[0].length) { Array.new(grid.length) } grid.each_with_index do |row, y| row.each_with_index do |col, x| transposed[x][y] = col end end vals = [] ops = [] temp_vals = [] transposed.each do |row| l = row.join("").strip temp_vals << l.scan(/\d+/).map(&:to_i).to_a[0] /[+*]/.match(l) { |m| ops << m.to_s.to_sym } if l == "" vals << temp_vals.compact temp_vals = [] end end vals << temp_vals.compact unless temp_vals.empty? vals.each_with_index.sum do |v, i| v.inject(ops[i]) end