From: Ummon Date: Tue, 10 Dec 2019 19:28:19 +0000 (+0100) Subject: Remove dependency to 'image' X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=476bc62cca2a2e08f8f3cae9c9eb459da3375560;p=advent_of_code_2019.git Remove dependency to 'image' --- diff --git a/Cargo.toml b/Cargo.toml index 7db3d01..c7438f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,4 @@ edition = "2018" # 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 diff --git a/src/day08.rs b/src/day08.rs index 0f1bb38..95b0385 100644 --- a/src/day08.rs +++ b/src/day08.rs @@ -47,9 +47,22 @@ pub fn merge_layers(layers: &[Vec]) -> Vec { result } -pub fn write_layer

>(layer: &[u8], width: u32, height: u32, to: P) { - let layer_normalized: Vec = 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 { diff --git a/src/main.rs b/src/main.rs index c388bbd..42699c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,12 +59,9 @@ fn day08() -> String { 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 {