Advent of Code 2022 Day 1

in #adventofcodelast year

Sorry that I am blogging via my phone and I don't want to type too much.
I will just share the finished codes.
You can see all of them on GitHub

Part 1

inputs <- readLines('https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/1')
elves <- c()
elf <- c()
for (input in inputs) {
    if (input != '') {
        elf[length(elf)+1L] <- as.integer(input)
    } else {
        elves[length(elves)+1L] <- sum(elf)
        elf <- c()
    }
}
cat(max(elves),'\n')

Part 2

inputs <- readLines('https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/1')
elves <- c()
elf <- c()
for (input in inputs) {
    if (input != '') {
        elf[length(elf)+1L] = as.integer(input)
    } else {
        elves[length(elves)+1L] = sum(elf)
        elf <- c()
    }
}
cat(sum(sort(elves)[(length(elves)-2L):length(elves)]))
Sort:  

Congratulations @lochard! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You published more than 20 posts.
Your next target is to reach 30 posts.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Check out our last posts:

The Hive Gamification Proposal