From d108e00be1a28e48ca88e0be5026263f08a2be2e Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 22 Nov 2020 00:14:20 -0500 Subject: Day 5 --- src/bin/day05.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/bin/day05.rs (limited to 'src/bin') 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")); +} -- cgit 1.4.1 commit diff
path: root/etc/tf/cfg (unfollow)
Commit message (Collapse)Author
2018-08-16Port all scripts to shJune McEnroe
Not hard, but having to escape ( ) inside [ ] had me confused for a bit.
2018-08-16Shorten .local ssh namesJune McEnroe
ksh doesn't do sophisticated tab-complete so I have to actually type ssh hosts now.
2018-08-16Export GPG_TTYJune McEnroe
Oops.
2018-08-16Disable visual bell entirely in TerminalJune McEnroe
You can't turn off bell in ksh.
2018-08-16Rearrange kshrc, fix right promptJune McEnroe