Skip to content

Instantly share code, notes, and snippets.

@ursulams
Created December 3, 2025 04:00
Show Gist options
  • Select an option

  • Save ursulams/a4b6032f13b4f4da0ad40cb53e100212 to your computer and use it in GitHub Desktop.

Select an option

Save ursulams/a4b6032f13b4f4da0ad40cb53e100212 to your computer and use it in GitHub Desktop.
2025 advent of code day 1
# first star
# swap out l/r for operators
input <- apply(read.table("input.txt", header = FALSE), 1,
function(x) gsub("L", "-", gsub("R", "+", x)))
input <- sapply(input, function(x) eval(parse(text = x)))
start <- 50
clicks <- cumsum(c(start,input))
# sum of t/f dial point = 0
sum(clicks %% 100 == 0)
# second star
counter <- 0
# iterate over each position on dial
for (i in seq_along(input)) {
position <- (start + input[i]) %% 100
counter <- counter + abs(input[i]) %/% 100 # trips around the dial
if (position == 0) {
counter <- counter + 1
} else if (sign(input[i]) * (position - start) < 0 & start != 0) {
counter <- counter + 1
}
start <- position
}
counter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment