Skip to content

Commit

Permalink
01 done
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Dec 16, 2024
1 parent 5ab4b7f commit e5dd580
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions _2024/_01/01.jule
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cpp use "helper.hpp"

cpp fn readIntegers(line: str, do_right: bool): int

fn calculateMetrics(input: []byte): str {
fn calculateMetrics(input: []byte): [2]int {
lines := strings::SplitAll(str(input), "\n")

let mut list_left: []int
Expand All @@ -32,15 +32,31 @@ fn calculateMetrics(input: []byte): str {
total += int(math::Abs(f64(l - list_right[i])))
}

print("total: ")
println(total)
let mut similarity: int = 0

ret ""
for _, l_num in list_left {
let mut count: int = 0
for _, r_num in list_right {
if l_num == r_num {
count++
}
}
similarity += l_num * count
}

ret [total, similarity]
}

fn Run() {
println("2024/01")

inputs := os::File.Read("_2024/_01/inputs.txt")!
println(calculateMetrics(inputs))
result := calculateMetrics(inputs)

print("total distance: ")
println(result[0])
print("similarity score: ")
println(result[1])
}

fn sum(values: ...int): int {
Expand Down

0 comments on commit e5dd580

Please sign in to comment.