use std::fs; fn solve_puzzle(lines: &Vec<&str>) -> [[bool; 6]; 50] { let mut pixels = [[false; 6]; 50]; for line in lines { let words: Vec<&str> = line.split_ascii_whitespace().collect(); if words[0] == "rect" { // Read operation parameters let wxh: Vec<&str> = words[1].split('x').collect(); let w: usize = wxh[0].parse().unwrap(); let h: usize = wxh[1].parse().unwrap(); // Apply operation to state for x in 0..w { for y in 0..h { pixels[x][y] = true; } } } else if words[0] == "rotate" && words[1] == "row" { // Read operation parameters let which: Vec<&str> = words[2].split('=').collect(); let y: usize = which[1].parse().unwrap(); let n: usize = words[4].parse().unwrap(); // Apply operation to state let mut old = Vec::new(); for x in 0..50 { old.push(pixels[x][y]); } for x in 0..50 { pixels[x][y] = old[(x + 50 - n) % 50]; } } else if words[0] == "rotate" && words[1] == "column" { // Read operation parameters let which: Vec<&str> = words[2].split('=').collect(); let x: usize = which[1].parse().unwrap(); let n: usize = words[4].parse().unwrap(); // Apply operation to state let old = pixels[x]; for y in 0..6 { pixels[x][y] = old[(y + 6 - n) % 6]; } } } pixels } fn main() { let input = fs::read_to_string("input.txt").unwrap(); let lines = input.lines().collect(); let pixels = solve_puzzle(&lines); // Part 2 must be read by eye, gives "UPOJFLBCEZ" for me println!("Part 2 solution:"); let mut total = 0; for y in 0..6 { print!("\t"); for x in 0..50 { print!( "{}", if pixels[x][y] { total += 1; '#' } else { ' ' } ); } print!("\n"); } // Part 1 gives 116 for me println!("Part 1 solution: {}", total); }