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.

  • @zogwarg
    link
    English
    2
    edit-2
    9 months ago
    a,b

    I 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
      link
      English
      29 months ago
      neat!

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