about summary refs log tree commit diff
path: root/aoc/2022/02/part-one.ha
blob: 7a49de0bb0552f9542a032202d29d52755ab0e89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use bufio;
use fmt;
use io;
use os;

fn scanbyte(file: io::handle) u8 = {
	match (bufio::scanbyte(os::stdin)!) {
	case let byte: u8 =>
		return byte;
	case io::EOF =>
		fmt::fatal("Unexpected EOF");
	};
};

export fn main() void = {
	let score: u16 = 0;
	for (true) {
		const them = 'D' - (match (bufio::scanbyte(os::stdin)!) {
		case let byte: u8 =>
			yield byte;
		case io::EOF =>
			break;
		});
		scanbyte(os::stdin);
		const us = scanbyte(os::stdin) - 'W';
		scanbyte(os::stdin);
		score += us + (us + them) % 3 * 3;
	};
	fmt::println(score)!;
};