## JavaScript (node.js) Counts what was most popular last round and bids one less than that, wrapping to 20 and bidding 3 on the first round. var lastRound = process.argv[2]; var numbers = {}; var matches = /\d+/g.exec(/[^\n]+$/.exec(lastRound)); var i; for(i = 0; i < matches.length; i++) { if(matches[i] in numbers) { numbers[i]++; } else { numbers[i] = 1; } } var maxKey = -1, maxValue = -1; for(i in numbers) { if(numbers[i] > maxValue) { maxKey = i; maxValue = numbers[i]; } } if(maxKey == 0) { // First round. Bid 3. console.log(3); } else if(maxKey == 1) { // Bid 20. console.log(20); } else { // Bid one less. console.log(maxKey - 1); } How to invoke: node script.js 'the argument'