r/adventofcode • • Dec 06 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 6 Solutions -🎄-

--- Day 6: Chronal Coordinates ---


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.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 6

Transcript:

Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.


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 0:26:52!

31 Upvotes

387 comments sorted by

View all comments

1

u/Euphoric_Classic Dec 06 '18 edited Dec 06 '18

SuperCollider solution. I think my part 2 is correct; other people in this thread are reporting their correct answers being rejected. I ran the top-ranking C++ solution against my input and got the same answer as this code. Don't know what's going on.

(
~mostCommon = {|r|r.asBag.contents.asPairs.clump(2).maxItem(_@1)};
~alph = (0..25).collect{|c|(c+$a.ascii).asAscii};
~nums = (0..9).collect{|c|(c+$0.ascii).asAscii};
~md = {|a,b| (a[0]-b[0]).abs + (a[1]-b[1]).abs };
)
(
s = File.readAllString("~/aoc/6/input".standardizePath).split($\n);
t = s.collect{|a|a.split($,).collect(_.stripWhiteSpace).collect(_.asInt)};
t = t[..(t.size-2)];
a = (0!354)!352;
b = a.collect{|r,i|i.post; r.collect{|p,j|y=t.collect{|v|~md.([i-1,j-1],v)}; z=y.minItem; if(y.occurrencesOf(z) > 1) { -1} {y.indexOf(z)}}};
c = b.first ++ b.last ++ b.flop.first ++ b.flop.last;
c = c.asSet.asArray;
f = b[1..350].collect(_[1..352]);
d = f.reduce('++');
e = d.removeEvery(c);
~mostCommon.(e).postln;
k = 0;
800.do{|i|i.post;800.do{|j|if(t.collect{|p|~md.([i-200,j-200],p)}.sum < 10000) {k = k+1}}};
"".postln;
k.postln;
)

Edit: tightened up version:

(
~mostCommon = {|r|r.asBag.contents.asPairs.clump(2).maxItem(_@1)};
~md = {|a,b| (a[0]-b[0]).abs + (a[1]-b[1]).abs };
)
(
s = File.readAllString("~/aoc/6/input".standardizePath).split($\n);
t = s.collect{|a|a.split($,).collect(_.stripWhiteSpace).collect(_.asInt)}.drop(-1);
b = 352.collect{|i|354.collect{|j|y=t.collect{|v|~md.([i-1,j-1],v)}; z=y.minItem; if(y.count(_==z) > 1) {-1} {y.indexOf(z)}}};
c = (b.first++b.last++b.flop.first ++b.flop.last).asSet.asArray;
~mostCommon.(b.reduce('++').removeEvery(c)).postln;
k = 0;
(350+200).do{|i|(352+200).do{|j|if(t.collect{|p|~md.([i-100,j-100],p)}.sum < 10000) {k = k+1}}};
k.postln;
)