From 8beb3262bcba369fea7b73c9e04da025e04f2c90 Mon Sep 17 00:00:00 2001 From: Thomas L Date: Sat, 10 Sep 2016 16:09:55 +0200 Subject: [PATCH] make solution more compact --- set1/fixed_xor/src/main.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/set1/fixed_xor/src/main.rs b/set1/fixed_xor/src/main.rs index fa4156f..500b9c1 100644 --- a/set1/fixed_xor/src/main.rs +++ b/set1/fixed_xor/src/main.rs @@ -4,7 +4,6 @@ extern crate env_logger; extern crate rustc_serialize; use rustc_serialize::hex::{FromHex, ToHex}; -use std::cmp::min; use std::io::{BufRead, stdin}; struct Pairwise(T); @@ -27,13 +26,7 @@ fn main() { for (line1, line2) in Pairwise(stdin.lock().lines().filter_map(|x| x.ok())) { match (line1.from_hex(), line2.from_hex()) { - (Ok(v1), Ok(v2)) => { - let mut out = Vec::with_capacity(min(v1.len(), v2.len())); - for (lhs, rhs) in v1.iter().zip(v2) { - out.push(lhs ^ rhs) - } - println!("{}", out.to_hex()) - }, + (Ok(v1), Ok(v2)) => println!("{}", v1.iter().zip(v2).map(|(a, b)| a ^ b).collect::>().to_hex()), (Err(e), _) => error!("{}", e), (_, Err(e)) => error!("{}", e) }