diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2024-12-03 18:47:51 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2024-12-03 18:47:57 +0100 |
| commit | 190f522242b2e91eb3213e828a26886aa7847f3a (patch) | |
| tree | 04122a22aa1e92d6f3efe21436d2e75650c1c4c1 /3/3.ha | |
| parent | 92524aa912db99becc1b3446d5b68b9cc089c721 (diff) | |
| download | aoc24-190f522242b2e91eb3213e828a26886aa7847f3a.tar.gz | |
Refactor and add tests
Folders need to have 'sensible' names for hare test to detect them.
Diffstat (limited to '3/3.ha')
| -rw-r--r-- | 3/3.ha | 31 |
1 files changed, 0 insertions, 31 deletions
@@ -1,31 +0,0 @@ -use fmt; -use io; -use os; -use regex; -use strings; -use strconv; - -export fn main() void = { - const in = io::drain(os::stdin)!; - const sin = strings::trim(strings::fromutf8_unsafe(in)); - const re = regex::compile(`mul\([0-9]+,[0-9]+\)`)!; - defer regex::finish(&re); - - const results = regex::findall(&re, sin); - defer regex::result_freeall(results); - let sum = 0; - for (const result .. results) { - for (let r .. result) { - const idx1 = strings::index(r.content, ','); - const idx2 = strings::index(r.content, ')'); - const arg1 = strings::sub(r.content, 4, idx1: size); - const arg2 = strings::sub(r.content, idx1: size + 1, idx2: size); - - const a1 = strconv::stoi(arg1)!; - const a2 = strconv::stoi(arg2)!; - sum += a1 * a2; - fmt::printfln("{} * {} = {}", a1, a2, a1 * a2)!; - }; - }; - fmt::printfln("{}", sum)!; -}; |
