From 9ea77b5c26697ea55ddc49a687fbefecac2b3323 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Mon, 2 Nov 2026 03:18:33 +0300 Subject: [PATCH] Update Advent of Code solutions for current V semantics --- 2022/07/ChAoSUnItY.v | 2 ++ 2023/02/JalonSolov.v | 4 ++-- 2023/02/jacksonmowry.v | 4 ++-- 2024/03/leodev.v | 4 ++-- 2024/05/leodev.v | 2 +- 2024/07/leodev.v | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/2022/07/ChAoSUnItY.v b/2022/07/ChAoSUnItY.v index 6236184..8565255 100644 --- a/2022/07/ChAoSUnItY.v +++ b/2022/07/ChAoSUnItY.v @@ -66,6 +66,7 @@ fn (mut fs FileSystem) update_parent_dir_size(size u32, parent usize) { match mut parent_node { DirNode { parent_node.size += size + fs.nodes[parent] = parent_node if grand_parent := parent_node.parent { fs.update_parent_dir_size(size, grand_parent) @@ -91,6 +92,7 @@ fn (mut fs FileSystem) add_node(node Node) { match mut current_node { DirNode { current_node.children << usize(index) + fs.nodes[fs.current_node] = current_node } else {} } diff --git a/2023/02/JalonSolov.v b/2023/02/JalonSolov.v index 246855c..a53dced 100644 --- a/2023/02/JalonSolov.v +++ b/2023/02/JalonSolov.v @@ -11,7 +11,7 @@ mut sum_of_powers := 0 for l in lines { game_num := l[5..].int() - draws := l[l.index(':')! + 1..].split(';').map(it.trim_space()) + draws := l[(l.index(':') or { panic('missing colon') }) + 1..].split(';').map(it.trim_space()) mut possible := true mut min_red := 0 mut min_green := 0 @@ -22,7 +22,7 @@ for l in lines { for cube in cubes { num_cubes := cube.int() - cube_color := cube[cube.index(' ')! + 1..] + cube_color := cube[(cube.index(' ') or { panic('missing space') }) + 1..] match cube_color { 'red' { diff --git a/2023/02/jacksonmowry.v b/2023/02/jacksonmowry.v index c056f08..b52caa4 100644 --- a/2023/02/jacksonmowry.v +++ b/2023/02/jacksonmowry.v @@ -17,10 +17,10 @@ fn main() { } fn part_2(input []string) !int { - return arrays.sum[int](input.map(it.split(': ')[1]).map(it.split_any(',;').map(it.trim_space().split(' '))).map(it.power())) + return arrays.sum[int](input.map(it.split(': ')[1]).map(it.split_any(',;').map(it.trim_space().split(' '))).map(power(it))) } -fn (s [][]string) power() int { +fn power(s [][]string) int { mut arr := [1, 1, 1] for hand in s { num := hand[0].int() diff --git a/2024/03/leodev.v b/2024/03/leodev.v index a8a021c..30df729 100644 --- a/2024/03/leodev.v +++ b/2024/03/leodev.v @@ -7,7 +7,7 @@ fn main() { mut re := regex.regex_opt(r'mul\(\d{1,3},\d{1,3}\)')! mut total := 0 for value in re.find_all_str(content) { - a, b := value[4..value.len - 1].split_once(',') or { panic(err) } + a, b := value[4..value.len - 1].split_once(',') or { panic('missing delimiter') } total += a.int() * b.int() } @@ -28,7 +28,7 @@ fn main() { continue } - a, b := content2[start + 4..end - 1].split_once(',') or { panic(err) } + a, b := content2[start + 4..end - 1].split_once(',') or { panic('missing delimiter') } total2 += a.int() * b.int() } diff --git a/2024/05/leodev.v b/2024/05/leodev.v index 2638d69..1192944 100644 --- a/2024/05/leodev.v +++ b/2024/05/leodev.v @@ -12,7 +12,7 @@ fn main() { break } - a, b := line.split_once('|') or { panic(err) } + a, b := line.split_once('|') or { panic('missing delimiter') } rules[a.int()] << b.int() rules2[b.int()] << a.int() } diff --git a/2024/07/leodev.v b/2024/07/leodev.v index 3025da3..ea1f5e9 100644 --- a/2024/07/leodev.v +++ b/2024/07/leodev.v @@ -6,7 +6,7 @@ fn main() { mut total1 := i64(0) mut total2 := i64(0) for line in lines { - expected_str, value_str := line.split_once(': ') or { panic(err) } + expected_str, value_str := line.split_once(': ') or { panic('missing delimiter') } expected := expected_str.i64() values := value_str.split(' ').map(it.i64())