make solution more compact

This commit is contained in:
Thomas L 2016-09-10 16:09:55 +02:00
parent 5b5c47fe15
commit 8beb3262bc

View file

@ -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: Iterator>(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::<Vec<u8>>().to_hex()),
(Err(e), _) => error!("{}", e),
(_, Err(e)) => error!("{}", e)
}