mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Slightly more consise update step.
This commit is contained in:
@@ -8,18 +8,13 @@ input <- read.csv(tc, header=FALSE, sep=" ")
|
|||||||
|
|
||||||
close(tc)
|
close(tc)
|
||||||
|
|
||||||
accs <- rowSums(abs(input[,7:9]))
|
perm <- order(rowSums(abs(input[,7:9])), rowSums(abs(input[,4:6])))
|
||||||
speeds <- rowSums(abs(input[,4:6]))
|
|
||||||
|
|
||||||
perm <- order(accs, speeds)
|
|
||||||
print(perm[1] - 1)
|
print(perm[1] - 1)
|
||||||
|
|
||||||
for (i in 1:100) {
|
for (i in 1:100) {
|
||||||
# Update positions, speeds
|
# Update positions, speeds
|
||||||
for (coord in 1:3) {
|
input[,4:6] <- input[,4:6] + input[,7:9]
|
||||||
input[,coord+3] <- input[,coord+3] + input[,coord+6]
|
input[,1:3] <- input[,1:3] + input[,4:6]
|
||||||
input[,coord] <- input[,coord] + input[,coord+3]
|
|
||||||
}
|
|
||||||
|
|
||||||
dups <- !(duplicated(input[,1:3]) | duplicated(input[,1:3], fromLast=TRUE))
|
dups <- !(duplicated(input[,1:3]) | duplicated(input[,1:3], fromLast=TRUE))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user