Created
December 3, 2025 04:00
-
-
Save ursulams/a4b6032f13b4f4da0ad40cb53e100212 to your computer and use it in GitHub Desktop.
2025 advent of code day 1
This file contains hidden or 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
| # 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