Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active May 14, 2019 01:46
Show Gist options
  • Save omas-public/6b71436c66a56dfbce26e384b5039fca to your computer and use it in GitHub Desktop.
Save omas-public/6b71436c66a56dfbce26e384b5039fca to your computer and use it in GitHub Desktop.
Paiza: エンジニアが死滅シタ世界
(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'));
(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