day1.ha (993B)
- // SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+aoc2023@hacktivis.me>
- // SPDX-License-Identifier: MIT
- use bufio;
- use strings;
- use ascii;
- use fmt;
- use os;
- use io;
- export fn main() void = {
- let total = 0u32;
- for(true) {
- const line = match(bufio::scanline(os::stdin)) {
- case let l: []u8 => yield l;
- case io::EOF => break;
- case => abort();
- };
- const line = strings::fromutf8(line)!;
- let val = 0u32;
- let iter = strings::iter(line);
- for(true) {
- match(strings::next(&iter)) {
- case let c: rune =>
- if(ascii::isdigit(c)) {
- let c = c: u32;
- val = (c - '0')*10;
- break;
- };
- case =>
- abort();
- };
- };
- let iter = strings::riter(line);
- for(true) {
- match(strings::next(&iter)) {
- case let c: rune =>
- if(ascii::isdigit(c)) {
- let c = c: u32;
- val += (c - '0');
- break;
- };
- case =>
- abort();
- };
- };
- fmt::printfln("= {}", val)!;
- total += val;
- };
- fmt::printfln("Total: {}", total)!;
- };