Skip to content

Instantly share code, notes, and snippets.

@codecontemplator
Last active December 5, 2021 21:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecontemplator/2e20ef28a522d894aa40072c928b006d to your computer and use it in GitHub Desktop.
Save codecontemplator/2e20ef28a522d894aa40072c928b006d to your computer and use it in GitHub Desktop.
input <- read.table("input.txt", header = FALSE) # the input was sligtly adjusted to be accepted by read.table
n <- dim(input)[1]
xs <- input[c(1, 3)]
xs <- xs - min(xs) + 1
ys <- input[c(2, 4)]
ys <- ys - min(ys) + 1
m <- matrix(0, max(ys), max(xs))
for (i in 1:n) {
x1 <- xs[i, 1]
x2 <- xs[i, 2]
y1 <- ys[i, 1]
y2 <- ys[i, 2]
cs <- cbind(y1:y2, x1:x2)
m[cs] <- m[cs] + 1
}
sum(m > 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment