Skip to content

Instantly share code, notes, and snippets.

@cyberbit
Created December 3, 2018 17:58
Show Gist options
  • Save cyberbit/268cb1e5cfd3c2e2782a3ed380c919e7 to your computer and use it in GitHub Desktop.
Save cyberbit/268cb1e5cfd3c2e2782a3ed380c919e7 to your computer and use it in GitHub Desktop.
part1 () {
let rows = _.split(this.input, '\n')
let grid = _.times(MAX_DIM * MAX_DIM, _.constant(0))
_.each(rows, v => {
let [x, y, w, h] = _
.chain(v.match(/#\d+ @ (\d+),(\d+): (\d+)x(\d+)/)) // separate parts
.tail() // discard full match
.map(Number) // cast to numbers
.value() // destructure to variables
let origin = x + y * MAX_DIM // top left corner of claim
_.each(_.range(h), hh => {
_.each(_.range(w), ww => {
let point = origin + ww + hh * MAX_DIM // unique point "index" in grid
grid[point]++ // tally the claim
})
})
})
let claims = _.countBy(grid, v => v > 1 ? 'over' : 'good')
this.solution1 = claims.over
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment