summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--.gitattributes6
-rw-r--r--.gitignore3
-rw-r--r--day1/part1/main.ha43
3 files changed, 52 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..2742e4d
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,6 @@
+* text=auto eol=lf
+
+# Older git versions try to fix line endings on images, this prevents it.
+*.png binary
+*.jpg binary
+*.ico binary
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7412340
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+*/*/part1
+*/*/part2
+*/*/input.txt
diff --git a/day1/part1/main.ha b/day1/part1/main.ha
new file mode 100644
index 0000000..4f9b2b2
--- /dev/null
+++ b/day1/part1/main.ha
@@ -0,0 +1,43 @@
+use os;
+use io;
+use fmt;
+use strings;
+use strconv;
+
+export fn main() void = {
+ const handle = os::open("input.txt")!;
+ defer io::close(handle)!;
+
+ let buf = io::drain(handle) as []u8;
+ defer free(buf);
+
+ let input = strings::fromutf8_unsafe(buf[..]);
+ let lines = strings::split(input, "\n")!;
+
+ let dial: i16 = 50;
+ let zeroes_seen: u16 = 0;
+
+ for (let line .. lines[..]) {
+ if (strings::hasprefix(line, "L")) {
+ dial -= strconv::stoi16(strings::ltrim(line, 'L'))!;
+ } else if (strings::hasprefix(line, "R")) {
+ dial += strconv::stoi16(strings::ltrim(line, 'R'))!;
+ } else {
+ continue;
+ };
+
+ for (dial < 0 || dial > 99) {
+ if (dial < 0) {
+ dial += 100;
+ } else if (dial > 99) {
+ dial -= 100;
+ };
+ };
+
+ if (dial == 0) {
+ zeroes_seen += 1;
+ };
+ };
+
+ fmt::printfln("Password: {}", zeroes_seen)!;
+};