Last active
May 14, 2019 01:46
-
-
Save omas-public/6b71436c66a56dfbce26e384b5039fca to your computer and use it in GitHub Desktop.
Paiza: エンジニアが死滅シタ世界
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
(stdin => { | |
// Define Function | |
const range = (len, start) => | |
Array.from(Array(len), (v, i) => i + start) | |
const zeroPadding = digit => n => n.padStart(digit, '0') | |
// Declare Variable | |
const inputs = stdin.toString().trim().split('\n'); | |
// Main Procedure | |
const result = (([len, start, end]) => { | |
return range(end - start + 1, start) | |
.map(zeroPadding(len)) | |
})(inputs[0].split(' ').map(Number)); | |
console.log(result.join('\n')) | |
})(require('fs').readFileSync('/dev/stdin', 'utf8')); |
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
(stdin => { | |
// Define Function | |
const convert = list => list.map(c => parseInt(c | |
.replace('g', 0) | |
.replace('c', 1) | |
.replace('p', 2)), 10) | |
const judge = (a, b) => ((b - a) + 3) % 3 | |
const countWinLose = fn => ((acc, [car, cdr]) => { | |
acc[fn(car, cdr)] += 1 | |
return acc | |
}) | |
// Declare Variable | |
const inputs = stdin.toString().trim().split('\n'); | |
// Main Procedure | |
const result = ((N, matrix) => { | |
const countTable = [0, 0, 0] // [draw, win, lose] | |
const countfn = countWinLose(judge) | |
return matrix.map(convert) | |
.reduce(countfn, countTable) | |
.slice(1) | |
})(inputs.shift(), inputs.map(v => v.split(' '))); | |
console.log(result.join('\n')) | |
})(require('fs').readFileSync('/dev/stdin', 'utf8')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment