Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active July 13, 2023 12:42
Show Gist options
  • Save omas-public/055f67b4e76c1bcf3bd5a9e1d0c80320 to your computer and use it in GitHub Desktop.
Save omas-public/055f67b4e76c1bcf3bd5a9e1d0c80320 to your computer and use it in GitHub Desktop.
const stream = require('fs').readFileSync('/dev/stdin', 'utf8').trim()
const cols = stream.split(' ')
const lines = stream.split('\n')
const matrix = lines.map(line => line.split(' '))
const fn = (N, C, matrix) => {
const f = (acc, [n, c]) => [
...acc.slice(0, n - 1), c, ...acc.slice(n)
]
const pairs = matrix.map(([n, c]) => [Number(n), c])
return pairs.reduce(f, Array(Number(N)).fill(C)).join('')
}
const [[N], , ...rest] = matrix
const [ns, [C]] = [rest.slice(0, -1), rest.at(-1)]
const result = fn(N, C, ns)
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment