Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active January 10, 2023 13:08
Show Gist options
  • Save omas-public/7923acfd0b41518f092568521b31ba6a to your computer and use it in GitHub Desktop.
Save omas-public/7923acfd0b41518f092568521b31ba6a to your computer and use it in GitHub Desktop.
const identity = v => v
const join = (sep = '\n') => array => array.join(sep)
const split = (sep = ' ') => string => string.split(sep)
const inputs = (file = '/dev/stdin') => {
const stream = require('fs').readFileSync(file, 'utf-8').trim()
const toArray = sep => fn => iter => Array.from(split(sep)(iter), fn)
return {
readCols: (fn = identity) => toArray(' ')(fn)(stream),
readRows: (fn = identity) => toArray('\n')(fn)(stream),
readStream: (fn = identity) => fn(stream),
readMatrix: (fn = identity) => toArray('\n')(identity)(stream)
.map(toArray(' ')(fn))
}
}
const outputs = v => {
const _print = fn => v => console.log(fn(v))
return {
toLine: () => _print(identity)(v),
toCols: () => _print(join(' '))(v),
toRows: () => _print(join('\n'))(v),
toJSON: () => _print(JSON.stringify)(v),
toMatrix: () => _print(join('\n'))(v.map(join(' ')))
}
}
// 即時実行関数(main)
(() => {
// define function
const fn = (n, p, m, q) => {
// ここに処理を書く
const autographsCosts = n * p
const penCosts = Math.ceil(n / m) * q
return autographsCosts + penCosts
}
// declare varriable
const [[n, p], [m, q]] = inputs().readMatrix(Number)
// processing
const result = fn(n, p, m, q)
// display
outputs(result).Line()
})()
100 110
20 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment