# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-itertools = "0.8"
-image = "0.22"
\ No newline at end of file
+itertools = "0.8"
\ No newline at end of file
result
}
-pub fn write_layer<P : AsRef<std::path::Path>>(layer: &[u8], width: u32, height: u32, to: P) {
- let layer_normalized: Vec<u8> = layer.iter().map(|v| v * 255).collect();
- let _ = image::save_buffer(to, &layer_normalized, width, height, image::Gray(8));
+pub fn layer_to_printable_string(layer: &[u8], width: u32) -> String {
+ let mut result = String::new();
+ let mut i = 0;
+
+ loop {
+ for _ in 0 .. width {
+ if layer[i] == 0 {
+ result += " ";
+ } else {
+ result += "█";
+ }
+ i += 1;
+ if i >= layer.len() { return result }
+ }
+ result += "\n";
+ }
}
pub fn one_digits_times_two_digits(layer: &[u8]) -> u32 {
let layers = day08::decode_image(&raw, 25, 6);
let layer = day08::layer_with_fewer_0(&layers[..]);
- let result = day08::merge_layers(&layers[..]);
+ let merged = day08::merge_layers(&layers[..]);
- let img_output = "data/day08.png";
- day08::write_layer(&result, 25, 6, img_output);
-
- format!("part1: {}, part2: {}", day08::one_digits_times_two_digits(layer), img_output)
+ format!("part1: {}, part2:\n{}", day08::one_digits_times_two_digits(layer), day08::layer_to_printable_string(&merged, 25))
}
fn day09() -> String {