Last active
April 9, 2017 02:46
-
-
Save json2d/ee51e1f6cc6ad10870159cbe57c4d9d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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