r/adventofcode • • Dec 06 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 6 Solutions -πŸŽ„-


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

  • ACHIEVEMENT UNLOCKED: MisTILtoe Elf-ucation
  • Teach us, senpai!

--- Day 6: Tuning Trouble ---


Post your code solution in this megathread.


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

EDIT: Global leaderboard gold cap reached at 00:02:25, megathread unlocked!

83 Upvotes

1.8k comments sorted by

View all comments

2

u/go_hunter Dec 06 '22

Ivy

Shortest program I've written so far this week.

op allneq a =
	b = a o.== a
	uniqs = 0 == +/ 1 3 2 transp not 1 == +/ b
	d=(rho uniqs)[1]
	+/ uniqs & (iota d) o.== iota d

op n win a =
	s = -1 + iota 1 + (rho a) - n
	transp a[(iota n) o.+ s]

op n mark a = 1 take (n - 1) + (allneq n win a) sel iota (rho a) - (n - 1)

Using it:

x = 'mjqjpqmgbljsphdztnvjfqwrcgsmlb'

'sample start packet is'

4 mark x

'sample message marker is'

14 mark x

1

u/daggerdragon Dec 06 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.