Published: 24 Jan 2023 › Updated: 24 Jan 2023
Advent of Code Day 2
Sorry that I am blogging via my phone and I don't want to type too much.
I will just share the finished code.
You can see all of them on GitHub.
Advent of Code 2022
Part 1
inputs <- readLines('https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/2')
choices <- list('A'=1L, 'B'=2L, 'C'=3L,
'X'=1L, 'Y'=2L, 'Z'=3L)
total <- 0L
for (input in inputs) {
inp <- strsplit(input, " ")
res <- choices[[inp[[1L]][2L]]] - choices[[inp[[1L]][1L]]]
if (res == 1L | res == -2L) {
total <- total + 6L
} else if (res == 0L) {
total <- total + 3L
}
total <- total + choices[[inp[[1L]][2L]]]
}
total
Part 2
inputs <- readLines('https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/2')
choices <- list('A'=1L, 'B'=2L, 'C'=3L,
'X'=-1L, 'Y'=0L, 'Z'=1L)
total <- 0L
for (input in inputs) {
inp <- strsplit(input, " ")
res <- choices[[inp[[1L]][2L]]]
choice <- choices[[inp[[1L]][1L]]] + res
if (choice == 4L) {
choice <- 1L
} else if (choice == 0L) {
choice <- 3L
}
res <- res * 3L + 3L
total <- total + res + choice
}
total
Leave Advent of Code Day 2 to:
Read more #adventofcode posts
Best Posts From Lochard
We have not curated any of lochard's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Lochard
- King's Cross - 45th month of persecution by CCP, LT &UK
- 43rd month, belongings stolen
- Another round of strong damage
- 41st month of humiliation, torture and other crimes
- This is not a prank
- How sick one has to be to take pleasure in drugging and indirectly molesting others?
- Has AI already surpassed humans in morality and emotion?
- Just a reminder that your fellow biped had been treated as non-human for 39 months
- Psychopathy (Chat with AI)
- [Solved] Oracle Linux 10 WiFi adpator not found