use std::io::{self, Read};
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
fn main() -> Result<()> {
let mut input = String::new();
io::stdin().read_to_string(&mut input)?;
let vector = parse(input);
part1(&vector, 3, 1);
part2(&vector);
Ok(())
}
fn part2(vector: &Vec<Vec<bool>>) {
let mut ans: usize = 1;
ans *= part1(&vector, 1, 1);
ans *= part1(&vector, 3, 1);
ans *= part1(&vector, 5, 1);
ans *= part1(&vector, 7, 1);
ans *= part1(&vector, 1, 2);
println!("{}", ans);
}
fn part1(vector: &Vec<Vec<bool>>, x: usize, y: usize) -> usize {
let mut x_co = 0;
let mut y_co = 0;
let mut value = 0;
loop {
if vector[y_co][x_co % 31] == true {
value += 1;
}
x_co += x;
y_co += y;
// we are adding the value and then checking so no `vector.len() - 1`
if vector.len() <= y_co {
break;
}
}
value
}
fn parse(input: String) -> Vec<Vec<bool>> {
let mut vector = vec![];
for (_y, line) in input.lines().enumerate() {
let mut vec = vec![false; 31];
for (x, char) in line.trim().chars().enumerate() {
if char == '#' {
vec[x] = true;
} else {
vec[x] = false;
}
}
vector.push(vec);
}
vector
}