generated from Rexcrazy804/advent-of-code-rust-flake-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path'
115 lines (98 loc) · 2.98 KB
/
'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
use adv_code_2024::*;
use anyhow::*;
use code_timing_macros::time_snippet;
use const_format::concatcp;
use itertools::Itertools;
use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::usize;
const DAY: &str = "12";
const INPUT_FILE: &str = concatcp!("input/", DAY, ".txt");
const TEST: &str = "\
RRRRIICCFF
RRRRIICCCF
VVRRRCCFFF
VVRCCCJFFF
VVVVCJJCFE
VVIVCCJJEE
VVIIICJJEE
MIIIIIJJEE
MIIISIJEEE
MMMISSJEEE
";
fn main() -> Result<()> {
start_day(DAY);
//region Part 1
println!("=== Part 1 ===");
assert_eq!(1930, part1(BufReader::new(TEST.as_bytes()))?);
let input_file = BufReader::new(File::open(INPUT_FILE)?);
let result = time_snippet!(part1(input_file)?);
println!("Result = {}", result);
//endregion
//region Part 2
// println!("\n=== Part 2 ===");
// todo!("Set the expected answer for the test input");
// assert_eq!(0, part2(BufReader::new(TEST.as_bytes()))?);
// let input_file = BufReader::new(File::open(INPUT_FILE)?);
// let result = time_snippet!(part2(input_file)?);
// println!("Result = {}", result);
//endregion
Ok(())
}
fn part1<R: BufRead>(reader: R) -> Result<usize> {
let mut garden_map: Vec<Vec<char>> = Vec::new();
for line in reader.lines() {
let line = line?;
garden_map.push(line.chars().collect_vec());
}
let garden_regions: HashMap<char, Vec<Regions>> = HashMap::new();
for (index, row) in garden_map.iter().enumerate() {
for (index, plot) in row.iter().enumerate() {}
}
todo!()
}
fn part2<R: BufRead>(reader: R) -> Result<usize> {
todo!()
}
struct Regions {
plant_type: char,
plots: HashSet<(usize, usize)>,
}
impl Regions {
fn new(plant_type: char) -> Self {
Self {
plant_type,
plots: HashSet::new(),
}
}
fn get_region_plots(&mut self, plant_position: (usize, usize), garden_map: &Vec<Vec<char>>) {
if garden_map[plant_position.0][plant_position.1] != self.plant_type {
return;
}
if !self.plots.insert(plant_position) {
return;
}
if plant_position.1 != 0 {
let next_position = (plant_position.0 - 1, plant_position.1);
self.get_region_plots(next_position, garden_map);
}
if plant_position.0 != garden_map.len() - 1 {
let next_position = (plant_position.0 + 1, plant_position.1);
self.get_region_plots(next_position, garden_map);
}
if plant_position.1 != 0 {
let next_position = (plant_position.0, plant_position.1 - 1);
self.get_region_plots(next_position, garden_map);
}
if plant_position.1 != garden_map[0].len() - 1 {
let next_position = (plant_position.0, plant_position.1 + 1);
self.get_region_plots(next_position, garden_map);
}
}
fn get_area(&self) -> usize {
self.plots.len()
}
fn get_perimetre(&self) -> usize {
}
}