From 051be932a389b8bc3ea5d4626575454844639066 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 27 Nov 2017 17:11:18 -0500 Subject: Move to 2016 directory --- src/bin/day05.rs | 71 -------------------------------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 src/bin/day05.rs (limited to 'src/bin/day05.rs') diff --git a/src/bin/day05.rs b/src/bin/day05.rs deleted file mode 100644 index eefa3df..0000000 --- a/src/bin/day05.rs +++ /dev/null @@ -1,71 +0,0 @@ -extern crate crypto; - -use std::io::{self, Read}; - -use crypto::digest::Digest; -use crypto::md5::Md5; - -fn solve1(input: &str) -> String { - let mut password = String::new(); - let mut index = 0u64; - - while password.len() < 8 { - let mut md5 = Md5::new(); - md5.input_str(input); - md5.input_str(&index.to_string()); - let digest = md5.result_str(); - - if &digest[0..5] == "00000" { - password.push_str(&digest[5..6]); - } - - index += 1; - } - - password -} - -fn solve2(input: &str) -> String { - let mut password = [None; 8]; - let mut index = 0u64; - - while !password.iter().all(Option::is_some) { - let mut md5 = Md5::new(); - md5.input_str(input); - md5.input_str(&index.to_string()); - let digest = md5.result_str(); - - if &digest[0..5] == "00000" { - if let Some(pos @ 0 ... 7) = digest[5..6].parse().ok() { - password[pos] = password[pos].or(digest[6..7].chars().next()); - } - } - - index += 1; - } - - password.iter() - .cloned() - .map(Option::unwrap) - .collect() -} - -fn main() { - let mut input = String::new(); - io::stdin().read_to_string(&mut input).unwrap(); - - println!("Part 1: {}", solve1(input.trim())); - println!("Part 2: {}", solve2(input.trim())); -} - -#[test] -#[ignore] -fn part1() { - assert_eq!("18f47a30", solve1("abc")); -} - -#[test] -#[ignore] -fn part2() { - assert_eq!("05ace8e3", solve2("abc")); -} -- cgit 1.4.1 2f084f7aa1cabbfc0aaa706125f16b2&follow=1'>bundle/jellybeans.vim (unfollow)
Commit message (Expand)Author
2013-03-12Remove vim-powerlineJune McEnroe
2013-02-03Update base16 and refheapJune McEnroe
2013-02-03Ignore plugin/private.vimJune McEnroe
2012-09-29Disable GUI dialogsJune McEnroe