diff options
| author | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2024-06-08 13:50:47 +0300 |
|---|---|---|
| committer | Orfeas <38209077+0xfea5@users.noreply.github.com> | 2024-06-08 13:50:47 +0300 |
| commit | 7be570c4a6e86fb7060f0bc06910ca57003dfe90 (patch) | |
| tree | a998f976596cb902cd8988d74f756b72660bc29c /day01/solution.nim | |
| parent | Day 21 (part1) (diff) | |
| download | aoc22-7be570c4a6e86fb7060f0bc06910ca57003dfe90.tar.gz aoc22-7be570c4a6e86fb7060f0bc06910ca57003dfe90.zip | |
Diffstat (limited to 'day01/solution.nim')
| -rw-r--r-- | day01/solution.nim | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/day01/solution.nim b/day01/solution.nim new file mode 100644 index 0000000..b17411a --- /dev/null +++ b/day01/solution.nim | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | import std/strutils | ||
| 2 | import std/algorithm | ||
| 3 | |||
| 4 | let content = readFile("./input.txt").splitLines() | ||
| 5 | |||
| 6 | var | ||
| 7 | sum = 0 | ||
| 8 | sums = newSeq[int]() | ||
| 9 | |||
| 10 | for line in content: | ||
| 11 | if line.isEmptyOrWhitespace(): | ||
| 12 | sums.add(sum) | ||
| 13 | sum = 0 | ||
| 14 | continue | ||
| 15 | sum += parseInt(line) | ||
| 16 | |||
| 17 | sort(sums, system.cmp[int], Descending) | ||
| 18 | |||
| 19 | echo sums[0] | ||
| 20 | echo sums[0]+sums[1]+sums[2] | ||
