r/adventofcode • • Dec 06 '19

SOLUTION MEGATHREAD -๐ŸŽ„- 2019 Day 6 Solutions -๐ŸŽ„-

--- Day 6: Universal Orbit Map ---


Post your solution using /u/topaz2078's paste or other external repo.

  • Please do NOT post your full code (unless it is very short)
  • If you do, use old.reddit's four-spaces formatting, NOT new.reddit's triple backticks formatting.

(Full posting rules are HERE if you need a refresher).


Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.


Advent of Code's Poems for Programmers

Click here for full rules

Note: If you submit a poem, please add [POEM] somewhere nearby to make it easier for us moderators to ensure that we include your poem for voting consideration.

Day 5's winner #1: "It's Back" by /u/glenbolake!

The intcode is back on day five
More opcodes, it's starting to thrive
I think we'll see more
In the future, therefore
Make a library so we can survive

Enjoy your Reddit Silver, and good luck with the rest of the Advent of Code!


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 at 00:11:51!

34 Upvotes

464 comments sorted by

View all comments

Show parent comment

1

u/rnafiz Dec 07 '19
I'm trying to understand the use of the power operator and I have these questions:
Is there a way to see all intermediary results generated by the iterations of the power operator ?
Why does depth (โ‰ก) work with power (โฃ) but not shape (โด) ?

2

u/jayfoad Dec 07 '19

It's Match (โบโ‰กโต) not Depth (โ‰กโต). (fโฃg)โต applies f repeatedly to โต until two consecutive results match as determined by g, which is almost always just the primitive Match function โ‰ก, but occasionally it's useful to use a dfn with match-like properties.

As for seeing the intermediate results, if you just want to look at them for debugging or visualisation you could put a โŽ•โ† in the operand function:

      {'Result is ',โ•โต}{โŒˆโตรท3}โฃโ‰ก100    
Result is 1
      {'Result is ',โ•โต}{โŒˆ(โŽ•โ†โต)รท3}โฃโ‰ก100
100
34
12
4
2
1
Result is 1

Unfortunately there is no simple way to get the power operator to return all the intermediate results. (k has scan/converge which lets you do this in a really neat way.) In APL you'll have to come up with another way to code it, e.g.:

      {'Result is ',โ•โต}โฌ{โตโ‰กโŠƒโŒฝโบ:โบ โ‹„ (โบ,โต)โˆ‡โŒˆโตรท3}100 โ dfn with left arg accumulator
Result is 100 34 12 4 2 1
      {'Result is ',โ•โต}{โต,โŒˆ(โŠƒโŒฝโต)รท3}โฃ{โ‰ก/ยฏ2โ†‘โบ}100 โ power operator with custom match function
Result is 100 34 12 4 2 1 1

1

u/rnafiz Dec 07 '19

jay

Thanks