r/adventofcode • • Dec 07 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 7 Solutions -๐ŸŽ„-

--- Day 7: Recursive Circus ---


Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).

Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Need a hint from the Hugely* Handyโ€  Haversackโ€ก of Helpfulยง Hints^ยค?

Spoiler


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

10 Upvotes

222 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Dec 08 '17 edited Dec 08 '17

you cant have a scriptblock/expression in the middle of a pipe, only to start, so i don think thatll work as suggested, and if you begin/process/end it like that, might as well just make it a filter-function like i did

edit: OH! i see what you did. yes!!!! i can!!

    } | % { $script:rev = @() } { $script:rev = @($_) + $script:rev } { $script:rev } | %{

worked perfect!

passthru is one of the best things on a function that does work on an object :)

yeah, this one took most of the day on/off at times. first stab was ugly ugly ugly until it finally worked, then was able to rework into a usable pipeline. the reverse was the biggest killer, trying to figure out how to "do it all in one"

  • had this list
  • get one chance to iterate it
  • need to iterate it in two directions, but cant do them at the same time cause of this damn subweight
  • .....

so yeah, the reverse is /kinda/ cheating cause it restarts the pipeline effectively, but eh... ;)

i had one version with add-member and a bunch of scriptmethods and attempts at recursive scriptmethods and it was just a clusterfuck of slowness, couldnt hardly debug it :)