-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cd3e58
commit bc0a18e
Showing
3 changed files
with
1,063 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// aoc_jule Copyright (C) 2024 Adam Perkowski | ||
// https://github.com/adamperkowski/aoc_jule | ||
// https://adventofcode.com/2024/day/2 | ||
|
||
use "std/conv" | ||
use "std/os" | ||
use "std/strings" | ||
|
||
fn isSafe(levels: []int): bool { | ||
let mut increasing = true | ||
let mut decreasing = true | ||
|
||
for i, l in levels { | ||
if i == 0 { | ||
continue | ||
} | ||
|
||
diff := l - levels[i-1] | ||
if diff < 1 || diff > 3 { | ||
ret false | ||
} | ||
if diff > 0 { | ||
decreasing = false | ||
} else if diff < 0 { | ||
increasing = false | ||
} | ||
} | ||
ret increasing || decreasing | ||
} | ||
|
||
fn countSafe(input: []byte): int { | ||
lines := strings::SplitAll(str(input), "\n") | ||
|
||
let mut safe_reports: int = 0 | ||
|
||
for _, line_b in lines { | ||
line := str(line_b) | ||
tokens := strings::SplitAll(line, " ") | ||
let mut levels: []int | ||
|
||
for _, token in tokens { | ||
levels = append(levels, conv::Atoi(token)!) | ||
} | ||
|
||
if isSafe(levels) { | ||
safe_reports++ | ||
} | ||
} | ||
|
||
ret safe_reports | ||
} | ||
|
||
fn Run() { | ||
println("\n2024/02") | ||
|
||
inputs := os::File.Read("_2024/_02/inputs.txt")! | ||
result := countSafe(inputs) | ||
|
||
print("safe reports: ") | ||
println(result) | ||
} |
Oops, something went wrong.