this post was submitted on 01 Dec 2023
18 points (100.0% liked)

NotAwfulTech

364 readers
1 users here now

a community for posting cool tech news you don’t want to sneer at

non-awfulness of tech is not required or else we wouldn’t have any posts

founded 1 year ago
MODERATORS
 

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.

you are viewing a single comment's thread
view the rest of the comments
[–] zogwarg@awful.systems 2 points 11 months ago* (last edited 11 months ago) (1 children)

a,bI took a very similar approach to parts a and b, with the difference that i was too lazy to do titling in each direction, and wanted to abuse regex so Instead i always titled up and rotated, which given my method of tilting up and rotating had some satisfying cancelling of transpose operations: https://github.com/zogwarg/advent-of-code/blob/main/2023/jq/14-b.jq

# Relevant portion
# oneCycle expects an array, of array of chars (3x3 eg: [[".","#","."],[".",".","."],["O",".","#"]])
def oneCycle:
  # Tilt UP          = T . MAP(scan) . T
  # Rotate           = T . MAP(reverse)
  # Titl UP . Rotate = T . MAP(scan) . Map(reverse) | T . T = Identity
  def tilt_up_rotate:
      transpose          # Gets subgroups    # Within each group,
                         # starring with "#" # In order 1 "#", x "O", y "." 
    | map( ("#" + add) | [ scan("#[^#]*")    | ["#", scan("O"), scan("\\.")] ] | add[1:])
    | map(reverse)
  ;
  # Tilt   North,            West,           South,            East
  tilt_up_rotate | tilt_up_rotate | tilt_up_rotate | tilt_up_rotate
;

JQ does allow some nice sortcuts sometimes, again transpose is nice to have.

[–] swlabr@awful.systems 2 points 11 months ago

neat!I need like 25 more IQ points before I think of using a transpose in any context