day3.ha (1086B)
- // SPDX-FileCopyrightText: 2023 Haelwenn (lanodan) Monnier <contact+aoc2023@hacktivis.me>
- // SPDX-License-Identifier: MIT
- use bufio;
- use os;
- use strings;
- use ascii;
- export fn main() void = {
- let symbols: [](size, size) = [];
- let numbers: [](size, size, rune) = [];
- for(let y = 0z; true; y += 1) {
- const line = match(bufio::read_line(os::stdin)) {
- case let l: []u8 => yield l;
- case io::EOF => break;
- case => abort();
- };
- const line = strings::fromutf8(line)!;
- let iter = strings::iter(line);
- for(let x = 0z; true; x += 1) {
- const c = match(strings::next(&iter)) {
- case let c: rune => yield c;
- case void => break;
- };
- if(c == '.') {
- continue;
- } else if(ascii::isdigit(c)) {
- append(numbers, (x, y, c));
- } else {
- // assume symbol
- append(symbols, (x, y));
- };
- };
- };
- for(let n = 0z; n < len(numbers); n += 1) {
- const num = numbers[n];
- for(let s = 0z; s < len(symbols); s += 1) {
- const sym = symbols[s];
- if(
- (math::absi(num.0 - sym.0) < 2) &&
- (math::absi(num.1 - sym.1) < 2)
- ) {
- };
- };
- };
- };