crazy4groovy
12/11/2017 - 5:07 AM

adventofcode.com/2017/day/6

adventofcode.com/2017/day/6

// noprotect

const rows = data().split('\t').map(i => +i)
const regCount = rows.length

const mem = []
let count = 0

while(mem.indexOf(rows.join()) === -1) {
  mem.push(rows.join())
  count += 1
  
  let maxRegCount = Math.max(...rows)
  let regIndex = rows.findIndex(r => r === maxRegCount)
  
  rows[regIndex] = 0
  
  while (maxRegCount > 0) {
    regIndex = (++regIndex) % regCount
    rows[regIndex] += 1
    maxRegCount -= 1
  }
}

console.log('count:', count)

const firstIndex = mem.indexOf(rows.join())
console.log('cycles:', mem.length - firstIndex)

function data() {
  return (`4	10	4	1	8	4	9	14	5	1	14	15	0	15	3	5`)
}