r/adventofcode • • Dec 07 '16

SOLUTION MEGATHREAD --- 2016 Day 7 Solutions ---

From all of us at #AoC Ops, we hope you're having a very merry time with these puzzles so far. If you think they've been easy, well, now we're gonna kick this up a notch. Or five. The Easter Bunny ain't no Bond villain - he's not going to monologue at you until you can miraculously escape and save the day!

Show this overgrown furball what you've got!


--- Day 7: Internet Protocol Version 7 ---

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


ALWAYS DIGGING STRAIGHT DOWN IS MANDATORY [?]

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!

14 Upvotes

180 comments sorted by

View all comments

Show parent comment

2

u/wzkx Dec 07 '16 edited Dec 07 '16

It was really hard to make it tacit. Half a day :)

t =: cutLF CR-.~fread '07.dat'

spl =: (<;.2@,)&']' NB. split into parts with ']'
div =: (<;.2@,)&'[' NB. divide into '....[' and '....]'(,'[')
arr =: [:|:[:div@>spl NB. array of parts, row 0 positive, row 1 in [...]

hasabba =: [:+./4(0 1 1-:(0 0 1{])=1 3 2{])\] NB. string has pattern 'abba'
v1 =: 1 0-:(hasabba@;"1)@arr NB. row 0 has 'abba', row 1 has not
echo +/ v1&> t

isaba =: 0 1-:(0 0{])=1 2{] NB. string is of pattern 'aba'
bab =: [:1 0 1&{&.>[:(#~isaba&>)3<\[:;0{arr NB. array of 'bab' strings
rw1 =: ;@(1&{)@arr NB. stringified row 1
v2 =: +./@(,&':'@(>@bab)+./@E."1 1 rw1) NB. ,':' for empty boxes
echo +/ v2&> t

They can be one-lined with v1 f. and v2 f.

1

u/Godspiral Dec 08 '16

cool parsing trick,

 ; (L:2)  ('[' cut L:0 ']'&cut) each t

odd indexes are hypernet.

1

u/wzkx Dec 09 '16

Thank you. I see. But all those L:x are still too magic for me. Probably worth learning and practicing.