commit c75efa5cd117c7cd77e394fde7edaff975b9ad2f
parent 4a66634bf2fbc7f386bff7b8800fcc4ba97da801
Author: Eamon Caddigan <eamon.caddigan@gmail.com>
Date: Thu, 1 Dec 2022 10:41:12 -0800
Rudimentary solution to day 1, part 1.
Diffstat:
A | day01.jl | | | 37 | +++++++++++++++++++++++++++++++++++++ |
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/day01.jl b/day01.jl
@@ -0,0 +1,37 @@
+#!/usr/bin/env julia
+
+#############################################################################
+# Part 1
+#############################################################################
+
+# Rejoice! Julia supports multi-line string literals
+part1_example = """
+ 1000
+ 2000
+ 3000
+
+ 4000
+
+ 5000
+ 6000
+
+ 7000
+ 8000
+ 9000
+
+ 10000
+ """
+
+# I'm sure this is hideous to Julia programmers.
+function solve1(input)
+ maximum([sum([parse(Int64, food) for food in split(inventory, "\n")])
+ for inventory = split(rstrip(input), "\n\n")])
+end
+
+@assert solve1(part1_example) == 24000
+
+# I found some code to download puzzle input from AoC, but I don't know how to
+# use other people's modules yet. So I'm just downloading the file to the local
+# directory for now. :/
+println("Part 1: ", solve1(read("day01_part1_input.txt", String)))
+