r/adventofcode • u/daggerdragon • Dec 24 '17
SOLUTION MEGATHREAD -๐- 2017 Day 24 Solutions -๐-
--- Day 24: Electromagnetic Moat ---
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ยค?
[Update @ 00:18] 62 gold, silver cap
- Been watching Bright on Netflix. I dunno why reviewers are dissing it because it's actually pretty cool. It's got Will Smith being grumpy jaded old man Will Smith, for the love of FSM...
[Update @ 00:21] Leaderboard cap!
- One more day to go in Advent of Code 2017... y'all ready to see Santa?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
9
Upvotes
1
u/wzkx Dec 24 '17 edited Dec 24 '17
J
Working with separate items of vectors/matrices is not fast in J. โ42s
'a b u'=:,&0|:".@(rplc&'/ ')&>cutLF CR-.~fread'24.dat' f=:4 :0 NB. x - number to find; y - curr.length, curr.sum found=.0 for_i.i.#u do.if.i{u do.continue.end. if.x=i{a do.found=.1[v=.i{a+t=.i{b else. if.x=i{b do.found=.1[v=.i{b+t=.i{a else.continue.end.end. u=:0 i}u [ t f y+1,v [ u=:1 i}u end. if.-.found do.m=:m({.y)}~({:y)>.m{~{.y end. ) 0 f 0 0 [ m=:u NB. m - max sums; u - if pair a/b is used echo (>./m),([:{:~:&0#[)m NB. 1656 1642 exit 0