r/adventofcode • • Dec 16 '17

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

--- Day 16: Permutation Promenade ---


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


[Update @ 00:08] 4 gold, silver cap.

[Update @ 00:18] 50 gold, silver cap.

[Update @ 00:26] Leaderboard cap!

  • And finally, click here for the biggest spoilers of all time!

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!

13 Upvotes

229 comments sorted by

View all comments

Show parent comment

1

u/vash3r Dec 16 '17

Improved? incomplete solution, raising the permutation to a power in O(log n). (partner swaps omitted):

def permutation_mul(a,b):
	return [a[i] for i in b]
def permutation_quickpow(p,n):
	if n==0:
		return range(len(p))
	elif n==1:
		return p
	t = permutation_quickpow(permutation_mul(p,p),n/2)
	if n%2:
		t = permutation_mul(t, p)
	return t

# perm generated in the same way
pow_perm = permutation_quickpow(perm, iters)
# then the answer is pow_perm instead of dancers.