Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn fold(lines: Vec<(char, usize)>, paper: &mut Vec<(usize, usize)>) {
- for (axis, mag) in lines.iter() {
- match axis {
- 'x' => {
- for (x, _) in paper.into_iter() {
- if *x > *mag {
- *x = *x - 2 * (*x - mag);
- }
- }
- }
- 'y' => {
- for (_, y) in paper.into_iter() {
- if *y > *mag {
- *y = *y - 2 * (*y - mag);
- }
- }
- }
- _ => unreachable!(),
- }
- }
- }
- fn prnt(paper: &[(usize, usize)]) {
- for y in 0_usize
- ..=(paper
- .iter()
- .fold(0, |ac, (_, el)| if *el > ac { *el } else { ac }))
- {
- for x in 0_usize
- ..=(paper
- .iter()
- .fold(0, |ac, (el, _)| if *el > ac { *el } else { ac }))
- {
- print!("{}", if paper.contains(&(x, y)) { "█" } else { " " });
- }
- println!();
- }
- }
- fn main() {
- let input = std::fs::read_to_string("inputs/input13.txt").unwrap();
- let input: Vec<_> = input.split('\n').collect();
- let input: Vec<_> = input.split(|x| *x == "").collect();
- let mut paper: Vec<_> = input[0]
- .iter()
- .map(|x| {
- let mut m = x.split(",");
- (
- m.next().unwrap().parse::<usize>().unwrap(),
- m.next().unwrap().parse::<usize>().unwrap(),
- )
- })
- .collect();
- let lines: Vec<_> = input[1]
- .iter()
- .map(|x| {
- let mut m = x.split(" ").nth(2).unwrap().split('=');
- (
- m.next().unwrap().parse::<char>().unwrap(),
- m.next().unwrap().parse::<usize>().unwrap(),
- )
- })
- .collect();
- fold(lines, &mut paper);
- paper.sort();
- paper.dedup();
- prnt(&paper);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement