commit 8a420bc40d67bfefea99dd116692711ac41025ee
parent d7a7e7d1f14478632441563cef9ab0ddfaf7850e
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Thu, 1 Dec 2022 16:32:09 -0800
Minor code tweaks
I'm not always going to go back and clean up solutions, but early on
it's probably worth doing—I'm learning this language, after all.
Diffstat:
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/day01.jl b/day01.jl
@@ -25,8 +25,8 @@ part1_example = """
# I'm sure this is hideous to Julia programmers.
# This function returns an array of the total snack calories for each elf
function snack_totals(input)
- [sum([parse(Int64, food) for food in split(inventory, "\n")])
- for inventory = split(rstrip(input), "\n\n")]
+ [sum(parse.(Int64, i))
+ for i = split.(split(rstrip(input), "\n\n"), "\n")]
end
function solve1(input)
@@ -45,7 +45,7 @@ println("Part 1: ", solve1(read("day01_part1_input.txt", String)))
#############################################################################
function solve2(input)
- sum(sort(snack_totals(input), rev=true)[1:3])
+ sum(partialsort(snack_totals(input), 1:3, rev=true))
end
@assert solve2(part1_example) == 45000