Slightly optimize string generation

This commit is contained in:
kageru 2021-12-13 11:43:08 +01:00
parent 310730482a
commit 74925b973d

View File

@ -4,6 +4,7 @@ use aoc2021::common::*;
use itertools::Itertools; use itertools::Itertools;
const DAY: usize = 13; const DAY: usize = 13;
// Turns out the grid is so sparse, a set would have been better. Welp.
type Parsed = (Vec<Vec<bool>>, Vec<Fold>); type Parsed = (Vec<Vec<bool>>, Vec<Fold>);
enum Fold { enum Fold {
@ -68,7 +69,8 @@ fn part2((grid, instructions): &Parsed) -> String {
for instruction in instructions { for instruction in instructions {
instruction.fold(&mut paper); // :thanking: instruction.fold(&mut paper); // :thanking:
} }
paper.into_iter().map(|ys| ys.into_iter().map(|b| if b { '#' } else { ' ' }).collect::<String>()).join("\n") const OUTPUT_CHARS: [char; 2] = [' ', '#'];
paper.into_iter().map(|ys| ys.into_iter().map(|b| OUTPUT_CHARS[b as usize]).collect::<String>()).join("\n")
} }
fn main() { fn main() {