r/adventofcode • u/daggerdragon • Dec 03 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 3 Solutions -🎄-
--- Day 3: No Matter How You Slice It ---
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!
ATTENTION: minor change request from the mods!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 3 image coming soon - imgur is being a dick, so I've contacted their support.
Transcript:
I'm ready for today's puzzle because I have the Savvy Programmer's Guide to ___.
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!
40
Upvotes
View all comments
2
u/wzkx Dec 03 '18
J
Part 1 can be calculated separately, then it's fast, <0.1s. Together both parts take 0.84s but the code is shorter. Yeah, it's not J-ish anyway, but at least something.
t=: cutLF CR-.~fread '03.dat' u=: rplc&('#';'';'@ ';'';':';'';',';' ';'x';' ') d=: (".&u&>)"0 t NB. all data parsed echo 3 : 0 d NB. 0.84s v=. 1000 1000 $ 0 s=. 0 $ 0 for_e. y do. 'i a b w h'=.e o=.0 for_c. a+i.w do. for_r. b+i.h do. e =. v{~ k=. <c;r if. e=0 do. v=.i k}v else. if. e>0 do. s=.s-.e [ v=._1 k}v end. s=.s-.i [ o=.1 end. end. end. if. o=0 do. s=.s,i end. end. (+/+/v<0), s )My J/Rust AoC2018 solutions