1use crate::util::grid::*;
9use crate::util::iter::*;
10use crate::util::parse::*;
11use crate::util::point::*;
12
13pub fn parse(input: &str) -> Vec<Point> {
14 let amounts = input.iter_signed::<i32>().chunk::<2>();
15 let mut points = Vec::new();
16
17 for (line, [a, b]) in input.lines().zip(amounts) {
18 if line.starts_with("rect") {
19 for x in 0..a {
20 for y in 0..b {
21 points.push(Point::new(x, y));
22 }
23 }
24 } else if line.starts_with("rotate row") {
25 for point in &mut points {
26 if point.y == a {
27 point.x = (point.x + b) % 50;
28 }
29 }
30 } else {
31 for point in &mut points {
32 if point.x == a {
33 point.y = (point.y + b) % 6;
34 }
35 }
36 }
37 }
38
39 points
40}
41
42pub fn part1(input: &[Point]) -> usize {
43 input.len()
44}
45
46pub fn part2(input: &[Point]) -> String {
47 let mut grid = Grid::new(50, 6, '.');
48
49 (0..6).for_each(|y| grid[Point::new(0, y)] = '\n');
50 input.iter().for_each(|&p| grid[p + RIGHT] = '#');
51
52 grid.bytes.iter().collect()
53}