use std::{
fs::File,
io::{prelude::*, BufReader},
};
fn main() {
let input = read_input("input.txt");
println!("part one: {}", part_one(&input));
}
fn read_input(filename: &str) -> Vec<Vec<char>> {
let file = File::open(filename).expect("no such file");
let buf = BufReader::new(file);
buf.lines()
.map(|l| -> Vec<char> {l.expect("Could not parse line").chars().collect()})
.collect()
}
fn part_one(input: &Vec<Vec<char>>) -> u32 {
let mut x = 0;
let mut y = 0;
let mut collisions = 0;
let width = input[0].len();
while y < input.len() {
if x >= width {
x = x - width;
}
if input[y][x] == '#' {
collisions += 1;
}
x += 3;
y += 1;
}
collisions
}
#[test]
fn test_read_input() {
let input = read_input("test_input.txt");
let first_char = input[0][0];
assert_eq!(first_char, '.')
}
#[test]
fn test_part_one() {
let input = read_input("test_input.txt");
assert_eq!(part_one(&input), 7)
}