Skip to content

Commit

Permalink
01 part 1 done
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Dec 16, 2024
1 parent bacbc43 commit 5ab4b7f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
47 changes: 45 additions & 2 deletions _2024/_01/01.jule
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,51 @@
// https://github.com/adamperkowski/aoc_jule
// https://adventofcode.com/2024/day/1

fn calculateMetrics(input: str) {}
use "std/math"
use "std/os"
use "std/slices"
use "std/strings"

cpp use "helper.hpp"

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

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

let mut list_left: []int
let mut list_right: []int

for _, line_b in lines {
line := str(line_b)
list_left = append(list_left, cpp.readIntegers(line, false))
list_right = append(list_right, cpp.readIntegers(line, true))
}

slices::Sort(list_left)
slices::Sort(list_right)

let mut total: int = 0

for i, l in list_left {
total += int(math::Abs(f64(l - list_right[i])))
}

print("total: ")
println(total)

ret ""
}

fn Run() {
println("Hello, world!")
inputs := os::File.Read("_2024/_01/inputs.txt")!
println(calculateMetrics(inputs))
}

fn sum(values: ...int): int {
let mut total: int = 0
for _, i in values {
total += i
}
ret total
}
19 changes: 19 additions & 0 deletions _2024/_01/helper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using namespace jule;

#include <iostream>
#include <sstream>
#include <string>

int readIntegers(const std::string& line, bool do_right) {
std::istringstream iss(line);
int left, right;
if (iss >> left >> right) {
if (do_right) {
return right;
} else {
return left;
}
} else {
std::cerr << "Error reading line: " << line << std::endl;
}
}

0 comments on commit 5ab4b7f

Please sign in to comment.