Day 7: Laboratories

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
[–] 1 point 10 months ago* (last edited 10 months ago)

Uiua

Part 1 was fun, though I had quite some frustration with getting the loop work the way I wanted it to.
For part 2 I didn't actually need to modify that much, just pass another function to deal with the list of tachyons: part 1, remove duplicates, part 2, don't remove and count at the end. Easy. Or so I thought.
I realized something was wrong when it just wouldn't stop running and the fan got louder.

Today I started over from scratch and decided to solve both parts at once since I basically got the counts for each row anyways, so I just had to change the way the splitting was handled.
There was one occasion where I got an error that the resulting array would be too big (~4GB) but at least I got a warning instead of seeing RAM usage spike suddenly :P

Run with example input

Code

$ .......S.......
$ ...............
$ .......^.......
$ ...............
$ ......^.^......
$ ...............
$ .....^.^.^.....
$ ...............
$ ....^.^...^....
$ ...............
$ ...^.^...^.^...
$ ...............
$ ..^...^.....^..
$ ...............
$ .^.^.^.^.^...^.
$ ...............
# &fras "input-7.txt" β—Œ
βŠœβˆ˜βŠΈβ‰ @\n
βŠƒ(=@SβŠ‘β‚€)(⊏⊚>0βŠΈβ‰‘/+=@^β†˜β‚‚)
ShootSplit ← (
  ‚(=2+>0)
  ⧻⊸⊚
  βŠ™(βŸœβ‚‚(
      βŸœβŠβŠšβŠ™βŸœ[β§»]
      ⍚(βŠ‚βŠƒ-₁+₁)
      /+β‰‘βŒŸ(⬚0Λœβ†―Γ—β—‡Β°βŠš)
    )
    +⍜⊏(Λœβ†―0β§»)⊚
  )
)

Solve ← (
  0
  β₯(βŠ™(+|ShootSplit|βŠƒβŠ‘β‚€β†˜β‚))β—‘β‹…β‹…β§»
  βŠŸβŠ™βŠ™β—ŒβŠ™/+
)

Solve
≑(&p $"Part _: _") 1_2

And for completeness sake:

Previous attemptEdit: Tried to scrape the old code together but seems like it doesn't actually work like this. Probably just some small thing I missed but I don't have the mental energy to take a look at this mess again :P

Prep ← βŠƒ(⊚=@S)βŠœβˆ˜βŠΈβ‰ @\n

Splits! ← (
  ˙⍀>0β—‘β‹…β§»
  ‚(=β§»β€™Λœβ¨‚)
  βˆ©βŒŸβ–½βŠΈΒ¬
  ⊸⧻
  βŠ™(♭≑[βŠƒ-₁+₁]
    ^βŠ‚)
)

Shoot! ← (
  0
  ⍒(βŠ™(+
    | ⍣Splits!^βŠΈβ‹…0
    | ⊚=@^Β°βŠ‚
    )
  | >0β‹…β‹…β§»)
)

PartOne ← (
  &fras "input-7.txt"
  Prep
  βŠ™β‹…β—ŒShoot!β—΄
)

PartTwo ← (
  &fras "input-7.txt"
  Prep
  β§»β‹…βŠ™β—ŒShoot!∘
)

  • source