summaryrefslogtreecommitdiff
path: root/2
diff options
context:
space:
mode:
authorJulian Hurst <julian.hurst@digdash.com>2024-12-03 18:47:51 +0100
committerJulian Hurst <julian.hurst@digdash.com>2024-12-03 18:47:57 +0100
commit190f522242b2e91eb3213e828a26886aa7847f3a (patch)
tree04122a22aa1e92d6f3efe21436d2e75650c1c4c1 /2
parent92524aa912db99becc1b3446d5b68b9cc089c721 (diff)
downloadaoc24-190f522242b2e91eb3213e828a26886aa7847f3a.tar.gz
Refactor and add tests
Folders need to have 'sensible' names for hare test to detect them.
Diffstat (limited to '2')
-rw-r--r--2/2.ha56
-rw-r--r--2/in6
2 files changed, 0 insertions, 62 deletions
diff --git a/2/2.ha b/2/2.ha
deleted file mode 100644
index 83ba3b8..0000000
--- a/2/2.ha
+++ /dev/null
@@ -1,56 +0,0 @@
-use fmt;
-use bufio;
-use os;
-use strings;
-use strconv;
-
-export fn main() void = {
- const sc = bufio::newscanner(os::stdin);
- defer bufio::finish(&sc);
-
- let safereports = 0;
- for (const line => bufio::scan_line(&sc)!) {
- const spl = strings::split(line, " ");
- defer free(spl);
- let safe = true;
- let inc: (bool | void) = void;
- for (let i = 1z; i < len(spl); i += 1) {
- const s1 = strconv::stoi(spl[i-1])!;
- const s2 = strconv::stoi(spl[i])!;
- const diff = if (s1 < s2) {
- match (inc) {
- case void =>
- inc = true;
- case let inc: bool =>
- if (!inc) {
- safe = false;
- break;
- };
- };
- yield s2 - s1;
- } else {
- match (inc) {
- case void =>
- inc = false;
- case let inc: bool =>
- if (inc) {
- safe = false;
- break;
- };
- };
- yield s1 - s2;
- };
- if (diff <= 0 || diff > 3) {
- safe = false;
- break;
- };
- };
- if (safe) {
- fmt::printfln("{}: Safe", line)!;
- safereports += 1;
- } else {
- fmt::printfln("{}: Unsafe", line)!;
- };
- };
- fmt::printfln("{} reports are safe", safereports)!;
-};
diff --git a/2/in b/2/in
deleted file mode 100644
index b49c10d..0000000
--- a/2/in
+++ /dev/null
@@ -1,6 +0,0 @@
-7 6 4 2 1
-1 2 7 8 9
-9 7 6 2 1
-1 3 2 4 5
-8 6 4 4 1
-1 3 6 7 9