[CLEANUP] Small code cleanup/fixes

This commit is contained in:
2020-12-11 21:43:12 +01:00
parent dec8510b25
commit 0a110d6bfd
3 changed files with 5 additions and 17 deletions

View File

@@ -7,7 +7,7 @@ pub fn solve() {
adapters.sort();
let diffs = count_diffs(&adapters);
println!("{:?}", diffs);
// println!("{:?}", diffs);
let part1 = (diffs[0] + 1) * (diffs[2] + 1);
println!("Day 10 Part 1: {}", part1);

View File

@@ -2,18 +2,17 @@ use super::util;
use crate::day11::GridState::Floor;
use crate::day11::GridState::FilledSeat;
use crate::day11::GridState::EmptySeat;
use usize_cast::{IntoUsize, FromUsize, IntoIsize, FromIsize};
pub fn solve() {
let lines = util::read_file("input/day11.txt");
let seats = Seats::parse(&lines);
let visible_chairs = seats.calculate_all_visible_chairs();
let part1 = solve_part1(&seats);
println!("Day 11 Part 1: {}", part1);
let visible_chairs = seats.calculate_all_visible_chairs();
let part2 = solve_part2(&seats, &visible_chairs);
println!("Day 11 Part 2: {}", part2);
@@ -108,9 +107,7 @@ impl Seats {
}
}
let mut seats = Seats { grid, width, height };
seats.calculate_all_visible_chairs();
return seats;
return Seats { grid, width, height };
}
fn calculate_all_visible_chairs(&self) -> Vec<Option<Vec<(usize, usize)>>> {
@@ -141,10 +138,9 @@ impl Seats {
fn raycast(&self, origin_x: &usize, origin_y: &usize, direction: &(i32, i32)) -> Option<(usize, usize)> {
let mut hit = false;
let mut x = *origin_x as i32;
let mut y = *origin_y as i32;
while !hit {
loop {
x = x + direction.0;
@@ -158,7 +154,6 @@ impl Seats {
return Option::Some((x as usize, y as usize));
}
}
return Option::None;
}
fn is_valid(&self, x: &i32, y: &i32) -> bool {
@@ -205,6 +200,7 @@ impl Seats {
self.grid[x + y * self.width] = state;
}
#[allow(dead_code)]
fn print(&self) {
for y in 0..self.height {

View File

@@ -10,12 +10,4 @@ pub fn read_file(filename: &str) -> Vec<String> {
res
}
pub fn add_to_usize(u: usize, i: i32) -> usize {
if i.is_negative() {
u - i.wrapping_abs() as u32 as usize
} else {
u + i as usize
}
}