Skip to content

Commit

Permalink
2023-02 (really, this time) (vlang#29)
Browse files Browse the repository at this point in the history
* 2023-02 (really, this time)

* fmt
  • Loading branch information
JalonSolov authored Dec 3, 2023
1 parent 105f1d0 commit ddbf5c8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 14 deletions.
65 changes: 65 additions & 0 deletions 2023/02/JalonSolov.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import os

const max_red = 12
const max_green = 13
const max_blue = 14

lines := os.read_lines('cube.input')!

mut sum_of_games := 0
mut sum_of_powers := 0

for l in lines {
game_num := l[5..].int()
draws := l[l.index(':')! + 1..].split(';').map(it.trim_space())
mut possible := true
mut min_red := 0
mut min_green := 0
mut min_blue := 0

for draw in draws {
cubes := draw.split(',').map(it.trim_space())

for cube in cubes {
num_cubes := cube.int()
cube_color := cube[cube.index(' ')! + 1..]

match cube_color {
'red' {
if num_cubes > max_red {
possible = false
}

if num_cubes > min_red {
min_red = num_cubes
}
}
'green' {
if num_cubes > max_green {
possible = false
}

if num_cubes > min_green {
min_green = num_cubes
}
}
'blue' {
if num_cubes > max_blue {
possible = false
}

if num_cubes > min_blue {
min_blue = num_cubes
}
}
else {}
}
}
}

sum_of_games += if possible { game_num } else { 0 }
sum_of_powers += min_red * min_green * min_blue
}

println('Part 1: ${sum_of_games}')
println('Part 2: ${sum_of_powers}')
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# adventofcode

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

Initial layout:

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

## Input file format

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

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

Note 2: there is a small script that can be used to verify that all
solutions continue to work with latest V versions. You can use it by
running `v run verify.v` in the top folder of this repository.
It will produce the necessary .out files for new solutions, and you
can just commit them, so that the CI will check that there are no
It will produce the necessary `.out` files for new solutions, and you
can commit them so that the CI will check that there are no
regressions.
2 changes: 2 additions & 0 deletions known_outputs/2023/02/JalonSolov.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Part 1: 8
Part 2: 2286

0 comments on commit ddbf5c8

Please sign in to comment.