Skip to content

Commit ddbf5c8

Browse files
authored
2023-02 (really, this time) (#29)
* 2023-02 (really, this time) * fmt
1 parent 105f1d0 commit ddbf5c8

File tree

3 files changed

+80
-14
lines changed

3 files changed

+80
-14
lines changed

2023/02/JalonSolov.v

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import os
2+
3+
const max_red = 12
4+
const max_green = 13
5+
const max_blue = 14
6+
7+
lines := os.read_lines('cube.input')!
8+
9+
mut sum_of_games := 0
10+
mut sum_of_powers := 0
11+
12+
for l in lines {
13+
game_num := l[5..].int()
14+
draws := l[l.index(':')! + 1..].split(';').map(it.trim_space())
15+
mut possible := true
16+
mut min_red := 0
17+
mut min_green := 0
18+
mut min_blue := 0
19+
20+
for draw in draws {
21+
cubes := draw.split(',').map(it.trim_space())
22+
23+
for cube in cubes {
24+
num_cubes := cube.int()
25+
cube_color := cube[cube.index(' ')! + 1..]
26+
27+
match cube_color {
28+
'red' {
29+
if num_cubes > max_red {
30+
possible = false
31+
}
32+
33+
if num_cubes > min_red {
34+
min_red = num_cubes
35+
}
36+
}
37+
'green' {
38+
if num_cubes > max_green {
39+
possible = false
40+
}
41+
42+
if num_cubes > min_green {
43+
min_green = num_cubes
44+
}
45+
}
46+
'blue' {
47+
if num_cubes > max_blue {
48+
possible = false
49+
}
50+
51+
if num_cubes > min_blue {
52+
min_blue = num_cubes
53+
}
54+
}
55+
else {}
56+
}
57+
}
58+
}
59+
60+
sum_of_games += if possible { game_num } else { 0 }
61+
sum_of_powers += min_red * min_green * min_blue
62+
}
63+
64+
println('Part 1: ${sum_of_games}')
65+
println('Part 2: ${sum_of_powers}')

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# adventofcode
22

3-
A repository for solutions to [Advent of Code](https://adventofcode.com/about) puzzles,
4-
written in the [V](https://vlang.io/) language.
3+
A repository for V language solutions to [Advent of Code](https://adventofcode.com/about) puzzles.
54

65
Initial layout:
76

@@ -16,26 +15,26 @@ your GitHub ID under the appropriate year/day subdir, and place all files there.
1615

1716
## Input file format
1817

19-
1. Input file should end with file extension `.input`
20-
2. Input file should be directly copied/pasted from AoC's example input with the following
18+
1. Input file should end with file extension `.input`
19+
2. Input file should be directly copied/pasted from AoC's example input with the following
2120
standard:
22-
- - No whitespace trimming (see note 1)
23-
- - No additional empty line
24-
- - No personal-specific input allowed in example input file
25-
3. If there are multiple example inputs for different parts in a day, suffix different
26-
input file with `-partX` where X is part number, then follow other citeria
21+
- No whitespace trimming (see Note 1 below)
22+
- No additional empty line
23+
- No personal-specific input allowed in example input file
24+
3. If there are multiple example inputs for different parts in a day, suffix each
25+
input file with `-partX` where X is part number, then follow other criteria
2726
4. Input file's name should relate to the corresponding AoC problem, for example: AoC 2022
2827
Day 7 relates to unix system's file system cmd operations, therefore, you should
29-
name it with`filesystem.input` or `cmd.input`
28+
name it `filesystem.input` or `cmd.input`
3029

31-
Note 1: when you add .input files, please turn off the auto trimming
32-
functionality of your editor/IDE. Some solutions require the .input
30+
Note 1: when you add `.input` files, please turn off the auto trimming
31+
functionality of your editor/IDE. Some solutions require the `.input`
3332
files to have the exact same format that AoC uses, and trimming end
3433
lines may break them.
3534

3635
Note 2: there is a small script that can be used to verify that all
3736
solutions continue to work with latest V versions. You can use it by
3837
running `v run verify.v` in the top folder of this repository.
39-
It will produce the necessary .out files for new solutions, and you
40-
can just commit them, so that the CI will check that there are no
38+
It will produce the necessary `.out` files for new solutions, and you
39+
can commit them so that the CI will check that there are no
4140
regressions.

known_outputs/2023/02/JalonSolov.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Part 1: 8
2+
Part 2: 2286

0 commit comments

Comments
 (0)