Skip to content

Commit

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

fn calculateMetrics(input: str) {}
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)

println(sum(list_left...))

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 abcb3f3

Please sign in to comment.