30

Day 1: Dusty Shed

Megathread guidelines

  • Keep top level comments as only solutions, if you want to say something other than a solution put it in a new post. (replies to comments can be whatever)
  • You can send code in code blocks by using three backticks, the code, and then three backticks or use something such as https://topaz.github.io/paste/ if you prefer sending it through a URL

FAQ

you are viewing a single comment's thread
view the rest of the comments
[-] Camille@lemmy.ml 3 points 1 day ago* (last edited 1 day ago)

Hare

Another year, another AOC! This year I'm doing it in Hare, because why not. As usual I started by writing a small library to fetch the day's input and to run each puzzle just by sending a function as callback. I don't see the point of sharing it unless people want to see the code.

part 1

type number_list = [](uint, uint);

fn cmpnblist(a: *opaque, b: *opaque) int = {
	const lhs = (*(a: *(uint, uint))).1: int;
	const rhs = (*(b: *(uint, uint))).1: int;

	return rhs - lhs;
};

fn up(list: *number_list, val: uint) void = {
	let length = len(list);
	for (let idx = 0z; idx < length; idx += 1) {
		const (v, count) = list[idx];
		if (v == val) {
			list[idx] = (v, count + 1);
			return;
		};		
	};

	append(list, (val, 1))!;
};

fn part1(scan: *bufio::scanner) (int | done) = {
	let numbers: number_list = alloc([], 0)!;
	defer free(numbers);

	for (true) {
		match (bufio::read_line(scan)) {
		case io::EOF => break;
		case let e: io::error => {
			log::printfln("error: {}", io::strerror(e));
			return done;
		};

		case let buf: []u8 => {
			const line = strings::fromutf8(buf)!;
			const val = strconv::stou(line)!;
			up(&numbers, val);	
		};
		};
	};

	sort::sort(numbers, size((uint, uint)), &cmpnblist)!;
	const highest3 = numbers[0..3];
	const factor = 1u;

	for (let (v, _) .. highest3) {
		factor *= v;
	};

	return factor: int;
};

part 2

fn part2(scan: *bufio::scanner) (int | done) = {
	let numbers: number_list = alloc([], 0)!;
	defer free(numbers);

	for (true) {
		match (bufio::read_line(scan)) {
		case io::EOF => break;
		case let e: io::error => {
			log::printfln("error: {}", io::strerror(e));
			return done;
		};

		case let buf: []u8 => {
			const line = strings::fromutf8(buf)!;
			const val = strconv::stou(line)!;
			up(&numbers, val);	
		};
		};
	};

	sort::sort(numbers, size((uint, uint)), &cmpnblist)!;
	const length = len(numbers);
	const lowest3 = numbers[length-3..length];
	const factor = 1u;

	for (let (v, _) .. lowest3) {
		factor *= v;
	};

	return factor: int;
};

this post was submitted on 01 Dec 2026
30 points (100.0% liked)

Advent Of Code

1262 readers
48 users here now

An unofficial home for the advent of code community on programming.dev! Other challenges are also welcome!

Advent of Code is an annual Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like.

Everybody Codes is another collection of programming puzzles with seasonal events.

EC 2025

AoC 2026

Solution Threads

M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12

Visualisations Megathread

Rules/Guidelines

Relevant Communities

Relevant Links

Credits

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

console.log('Hello World')

founded 3 years ago
MODERATORS