▲ 18 ▼ The official awful.systems Advent of Code 2023 thread (awful.systems) submitted 2 years ago* (last edited 2 years ago) by gerikson@awful.systems to c/notawfultech@awful.systems 121 comments fedilink hide all child comments Rules: no spoilers. The other rules are made up as we go along. Share code by link to a forge, home page, pastebin (Eric Wastl has one here) or code section in a comment.
[–] gerikson@awful.systems [S] 4 points 2 years ago (1 child) Day 14: Parabolic Reflector Dish I only managed part 1 today. My enthusiasm for index fiddling is waning rapidly. permalink fedilink source hideshow 1 child comment replies: [–] zogwarg@awful.systems 4 points 2 years ago How about not fiddling with indices? JQ Notfiddlingwithindexificationhttps://github.com/zogwarg/advent-of-code/blob/main/2023/jq/14-a.jq #!/usr/bin/env jq -n -R -f # Dish to grid [ inputs / "" ] # Tilt UP | transpose # Transpose, for easier RE use | map( # ("#" + add) | [ # For each column, replace '^' with '#' scan("#[O.]*") | [ # From '#' get empty spaces and 'O' rocks "#", scan("O"), scan("\\.") # Let gravity do it's work. ] # ] | add[1:] # Add groups back together ) # | transpose # Transpose back # For each row, count 'O' rocks | map(add | [scan("O")] | length) # Add total load on "N" beam | [0] + reverse | to_entries | map( .key * .value ) | add Similarly tired with index fiddling, I was pretty happy with my approach, which led to satisfying transpose cancelling in part 2. Not the fastest code out there, but it works. Day 14 was actually my favorite one so far ^^. permalink fedilink source parent
[–] zogwarg@awful.systems 4 points 2 years ago How about not fiddling with indices? JQ Notfiddlingwithindexificationhttps://github.com/zogwarg/advent-of-code/blob/main/2023/jq/14-a.jq #!/usr/bin/env jq -n -R -f # Dish to grid [ inputs / "" ] # Tilt UP | transpose # Transpose, for easier RE use | map( # ("#" + add) | [ # For each column, replace '^' with '#' scan("#[O.]*") | [ # From '#' get empty spaces and 'O' rocks "#", scan("O"), scan("\\.") # Let gravity do it's work. ] # ] | add[1:] # Add groups back together ) # | transpose # Transpose back # For each row, count 'O' rocks | map(add | [scan("O")] | length) # Add total load on "N" beam | [0] + reverse | to_entries | map( .key * .value ) | add Similarly tired with index fiddling, I was pretty happy with my approach, which led to satisfying transpose cancelling in part 2. Not the fastest code out there, but it works. Day 14 was actually my favorite one so far ^^. permalink fedilink source parent