forked from Nearsoft/google-code-jam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathd1000000.js
More file actions
26 lines (22 loc) · 715 Bytes
/
d1000000.js
File metadata and controls
26 lines (22 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const fs = require('fs');
// Read the input file and store the contents as a string
const input = fs.readFileSync('ts1_input.txt', 'utf8');
// Split the string into an array of lines
const inputLines = input.trim().split('\n');
// Iterate over the array of lines, skipping every other line
for (let i = 2; i < inputLines.length; i += 2) {
console.log("Case #"+(i/2)+": "+maxDiceLength(inputLines[i]));
}
console.log("Finished!")
function maxDiceLength(inputStr){
let length=0;
let die=inputStr.split(" ")
for(let i=0;i<die.length;++i){
die[i]=Number(die[i]);
}
die=die.sort(function(a, b) {return a - b;});
for(let i=0;i<die.length;++i){
if(die[i]>length) ++length;
}
return length;
}