create account

Advent of Code 2022 Day 1 by lochard

View this thread on: hive.blogpeakd.comecency.com
· @lochard ·
$0.02
Advent of Code 2022 Day 1
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](https://github.com/locharp/code-snippets/tree/main/AdventOfCode/2022)

**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)]))
```
👍  , , ,
properties (23)
authorlochard
permlinkadvent-of-code-2022-day
categoryadventofcode
json_metadata{"links":["https://github.com/locharp/code-snippets/tree/main/AdventOfCode/2022","https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/1","https://raw.githubusercontent.com/locharp/code-snippets/main/AdventOfCode/2022/inputs/1"],"image":[""],"tags":["adventofcode","2022","programming","code","r"],"description":"","app":"ecency/3.0.30-vision","format":"markdown+html"}
created2023-01-23 11:13:54
last_update2023-01-23 11:13:54
depth0
children1
last_payout2023-01-30 11:13:54
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length957
author_reputation1,822,854,321,066
root_title"Advent of Code 2022 Day 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,122,016
net_rshares45,819,543,499
author_curate_reward""
vote details (4)
@hivebuzz ·
Congratulations @lochard! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@lochard/posts.png?202301231246"></td><td>You published more than 20 posts.<br>Your next target is to reach 30 posts.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@lochard) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Check out our last posts:**
<table><tr><td><a href="/hive-139531/@hivebuzz/proposal-2324"><img src="https://images.hive.blog/64x128/https://i.imgur.com/RNIZ1N6.png"></a></td><td><a href="/hive-139531/@hivebuzz/proposal-2324">The Hive Gamification Proposal</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-lochard-20230123t133231
categoryadventofcode
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2023-01-23 13:32:30
last_update2023-01-23 13:32:30
depth1
children0
last_payout2023-01-30 13:32:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length945
author_reputation368,370,953,085,006
root_title"Advent of Code 2022 Day 1"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,124,115
net_rshares0