Skip to content

Instantly share code, notes, and snippets.

@json2d
Last active April 9, 2017 02:46
Show Gist options
  • Save json2d/ee51e1f6cc6ad10870159cbe57c4d9d2 to your computer and use it in GitHub Desktop.
Save json2d/ee51e1f6cc6ad10870159cbe57c4d9d2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const solveWith = require('./lib/solve-with')
var stall = (input) => {
var [N,K] = input.split(' ')
var lastChains = [];
var curChains = [N];
var ppl = K;
while(true) {
console.log('# chains:',curChains.length, '| sorting...');
lastChains = curChains.sort().reverse();
console.log('waiting for stall:',ppl,'| chains being processed:', lastChains.length);
curChains = [];
for(var i in lastChains) {
var s = lastChains[i]-1
var max = Math.ceil(s/2)
var min = s-max
ppl --;
if(ppl == 0) {
return max + " " + min
}else{
curChains.push(max)
curChains.push(min);
}
}
}
}
solveWith(stall,process.argv[2],process.argv[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment