Day 9: Movie Theater

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

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

Uiua

Part 1 was easy, part 2 is ...less so...

a hint that might help youvisualising the data reveals some interesting patterns. Follow link to do so.

Any way, here's my Part 1 while I'm still thinking about this.

# AOC 2025 Day 09
# Experimental!
D ← &fras"AOC2025day09.txt"  # Drop your file here and edit name
/β†₯/Γ—+1βŒ΅β‰/-⍉₂⧅<2β‹•Β°csv D       # Part 1 
βˆ§βœβŠ‘β‹…1⟜(Λœβ†―0+1/β†₯)βœβ‰β‰‘βœβ†βŠ›β‹•Β°csv D # Visualised data

Part 2

This is basically me thinking out loud, so it's untidy, brutal, repetitive and slow. (20s in the pad) link if you care

# Experimental!
# AOC 2025 Day 09
D     ← "7,1\n11,1\n11,7\n9,7\n9,5\n2,5\n2,3\n7,3"
D     ← &fras"AOC2025day09.txt" # Drop your file here and edit name
Parse ← β‹•Β°csv
Part₁ ← /β†₯/Γ—+1βŒ΅β‰/-⍉₂⧅<2

Squeeze ← βœβ‰β‰‘βœβ†βŠ›          # Squeeze (add a sort to inspect)
Draw    ← βˆ§βœβŠ‘β‹…1⟜(Λœβ†―0+1/β†₯) # Draw

HLines ← (
  Squeeze Parse D
  β†βŠ•(░⍆)βŠ›βŠΈβ‰‘βŠ’
  βˆ§β—‡(⍜⊑˜⍜(⊏|Λ™=)βŠ™Λœβˆ˜βŠƒ(⊒⊒|β†˜βŠ™β‡‘Β°βŠŸ+0_1βŠ£β‰))
)

VLines ← (
  Squeeze Parse D
  β†βŠ•(░⍆)βŠ›βŠΈβ‰‘βŠ£
  βˆ§β—‡(⍜⊑˜⍜(⊏|Λ™=)βŠ™Λœβˆ˜βŠƒ(⊣⊣|β†˜βŠ™β‡‘Β°βŠŸ+0_1βŠ’β‰))
)
DrawBorder ← βœβ‰VLines HLines Λœβ†―0β†―2+1/β†₯β™­Squeeze Parse D # Draws full border

# DrawBorder Squeeze # running this shows these as key boundary points -> [219 121] [219 123]
# βŠβ‰‘βŒŸΛœβ¨‚[[219 121] [219 123]]⊸Squeeze # which map to -> [[94985 48652][94985 50114]]
# leftmost -> only look left, rightmost-> only look right
# SO, now fill the shape to make this easier.
Fill ← (
  βŠ™βŠ™1           # fill colour.
  Good ← =0βŠ™β—ŒβŠ‘βŠ’ # Needs filling. Simple edges-check.
  # Take first of list. If needs fill, do so and then add
  # its four neighbours into queue. Repeat until queue is empty.
  ⍒(⨬(β†˜1|β—΄βŠ‚+Aβ‚‚Β€Β°βŠ‚ βŠƒ(β‹…βˆ˜|∘|β‹…β‹…β‹…βˆ˜)β—‘(⍜(⊑|β‹…βˆ˜)⊒))β—‘Good
  | >0β§»)
  β‹…βŠ™β‹…
)
DrawBorder     # Comment out everything below here to view the boundary.
Fill [219_120] # Now fill that boundary ([2_1] for test)
Squeeze Parse D
# ([0 1] for test)
[219 123] #  [219 121] gave the wrong answer, so it's this.
β‰‘βŒžβŠŸ       # couple this with every other point
# Extract the covered window of the array for each pair of corners.
# (Very probably doing this the hard way:-()
# Only keep those that are all 1.
β–½β€šβ‰‘βŒŸ(=1/Γ—β™­β‰‘βŒžβŠβŠ™βŠΛœβˆ˜βˆ©(β†˜βŠ™β‡‘Β°βŠŸ+0_1⍆)Β°βŠŸβ‰)
# Pick out our squeezed indices
⨂Squeeze Parse D
# Find out what the unsqueezed values were
˜⊏Parse D
# Find areas, return max.
/β†₯≑/Γ—+1βŒ΅β‰‘/-
  • source
  • hideshow 2 child comments