Last active
December 5, 2021 21:04
-
-
Save codecontemplator/2e20ef28a522d894aa40072c928b006d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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