diff options
| author | June McEnroe <june@causal.agency> | 2020-11-22 00:14:20 -0500 |
|---|---|---|
| committer | June McEnroe <june@causal.agency> | 2020-11-22 00:14:20 -0500 |
| commit | f8386c60fc12eab66f863b0184b552dd5326beda (patch) | |
| tree | 2534b11fc36a9691cf9d02cc31f0ee5ec8e35394 /src/bin | |
| parent | Use math to rotate in day 4 (diff) | |
| download | aoc-f8386c60fc12eab66f863b0184b552dd5326beda.tar.gz aoc-f8386c60fc12eab66f863b0184b552dd5326beda.zip | |
Day 5
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/day05.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bin/day05.rs b/src/bin/day05.rs new file mode 100644 index 0000000..a860e53 --- /dev/null +++ b/src/bin/day05.rs @@ -0,0 +1,39 @@ +extern crate crypto; + +use std::io::{self, Read}; + +use crypto::digest::Digest; +use crypto::md5::Md5; + +fn solve(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 main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + + println!("Part 1: {}", solve(input.trim())); +} + +#[test] +#[ignore] +fn part1() { + assert_eq!("18f47a30", solve("abc")); +} |