Skip to content

Commit

Permalink
not work :(
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Dec 16, 2024
1 parent 0cd3e58 commit bc0a18e
Show file tree
Hide file tree
Showing 3 changed files with 1,063 additions and 0 deletions.
61 changes: 61 additions & 0 deletions _2024/_02/02.jule
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)
}
Loading

0 comments on commit bc0a18e

Please sign in to comment.