89 lines
1.8 KiB
Rust
89 lines
1.8 KiB
Rust
|
use aoc_runner_derive::{aoc, aoc_generator};
|
||
|
|
||
|
#[derive(Debug)]
|
||
|
enum Rock {
|
||
|
Round,
|
||
|
Square,
|
||
|
None
|
||
|
}
|
||
|
trait RockConvertable {
|
||
|
fn to_rock(&self) -> Rock;
|
||
|
}
|
||
|
|
||
|
impl RockConvertable for char {
|
||
|
fn to_rock(&self) -> Rock {
|
||
|
match self {
|
||
|
'O' => Rock::Round,
|
||
|
'#' => Rock::Square,
|
||
|
'.' => Rock::None,
|
||
|
_ => panic!("Invalid rock char")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[aoc_generator(day14)]
|
||
|
fn parse(input: &str) -> Vec<Vec<Rock>> {
|
||
|
let input: Vec<Vec<Rock>> = input.lines()
|
||
|
.map(|line| {
|
||
|
line.chars().map(|char| {
|
||
|
char.to_rock()
|
||
|
}).collect::<Vec<_>>()
|
||
|
}).collect::<Vec<_>>();
|
||
|
input
|
||
|
}
|
||
|
|
||
|
#[aoc(day14, part1)]
|
||
|
fn part1(input: &Vec<Vec<Rock>>) -> usize {
|
||
|
let mut load: usize = 0;
|
||
|
for j in 0..input[0].len() {
|
||
|
let mut cur_weight = input[0].len() + 1;
|
||
|
|
||
|
for i in 0..input.len() {
|
||
|
match input[i][j] {
|
||
|
Rock::Round => {
|
||
|
cur_weight -= 1;
|
||
|
load += cur_weight;
|
||
|
//println!("{}", cur_weight);
|
||
|
},
|
||
|
Rock::Square => {
|
||
|
//println!("{}", input[0].len() - i);
|
||
|
cur_weight = input[0].len() - i;
|
||
|
},
|
||
|
Rock::None => continue
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
load
|
||
|
}
|
||
|
|
||
|
// #[aoc(day14, part2)]
|
||
|
// fn part2(input: &Vec<Vec<Rock>>) -> String {
|
||
|
// todo!()
|
||
|
// }
|
||
|
|
||
|
|
||
|
#[cfg(test)]
|
||
|
mod tests {
|
||
|
use super::*;
|
||
|
|
||
|
const EX: &str = r"O....#....
|
||
|
O.OO#....#
|
||
|
.....##...
|
||
|
OO.#O....O
|
||
|
.O.....O#.
|
||
|
O.#..O.#.#
|
||
|
..O..#O..O
|
||
|
.......O..
|
||
|
#....###..
|
||
|
#OO..#....";
|
||
|
|
||
|
#[test]
|
||
|
fn part1_example() {
|
||
|
assert_eq!(part1(&parse(EX)), 136);
|
||
|
}
|
||
|
|
||
|
// #[test]
|
||
|
// fn part2_example() {
|
||
|
// assert_eq!(part2(&parse(EX)), "<RESULT>");
|
||
|
// }
|
||
|
}
|