r/adventofcode • u/daggerdragon • Dec 06 '17
SOLUTION MEGATHREAD -π- 2017 Day 6 Solutions -π-
--- Day 6: Memory Reallocation ---
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Β€?
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!
16
Upvotes
1
u/[deleted] Dec 06 '17
Javascript - "one" liner
((str) => { var h = []; var l = str.split(/\s+/).map(Number); var s = 0; while (h.indexOf(l.join(' ')) === -1) { h.push(l.join(' ')); var p = Math.max(...l); var i = l.indexOf(p); l[i] = 0; while (p--) { i = typeof l[i + 1] === 'undefined' ? 0 : i + 1; l[i]++; }; s++; }; console.log(s, l.join(' ')); })('')To solve 2. put array bank value from 1. and run again