summaryrefslogtreecommitdiffstats
path: root/2015/rs/code/four
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2023-11-20 17:12:15 -0500
committeralyx <alyx@aleteoryx.me>2023-11-20 17:12:15 -0500
commitccf1a5828fc26a82545c7accf1ce7916daa08a2d (patch)
tree2428c1374e8f9bcbfd00c8090606f4781d083401 /2015/rs/code/four
parent4810e24657a5931ea79be3fc3ee3e108fe40282e (diff)
downloadadventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.gz
adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.tar.bz2
adventofcode-ccf1a5828fc26a82545c7accf1ce7916daa08a2d.zip
Reorganize using workspaces
Diffstat (limited to '2015/rs/code/four')
-rw-r--r--2015/rs/code/four/Cargo.toml9
-rw-r--r--2015/rs/code/four/src/main.rs46
2 files changed, 55 insertions, 0 deletions
diff --git a/2015/rs/code/four/Cargo.toml b/2015/rs/code/four/Cargo.toml
new file mode 100644
index 0000000..ab76142
--- /dev/null
+++ b/2015/rs/code/four/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "four"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+md-5 = "0.10.6"
diff --git a/2015/rs/code/four/src/main.rs b/2015/rs/code/four/src/main.rs
new file mode 100644
index 0000000..177ddc5
--- /dev/null
+++ b/2015/rs/code/four/src/main.rs
@@ -0,0 +1,46 @@
+use md5::{Digest, Md5};
+use std::fmt::Write;
+use std::io::Write as WriteI;
+
+static INPUT: &'static [u8] = b"yzbqklnj";
+
+fn main() {
+ let mut buf = Vec::with_capacity(INPUT.len() + 10);
+ buf.extend_from_slice(INPUT);
+
+ for i in 0.. {
+ if i % 1000 == 0 { print!("{i}\r"); std::io::stdout().flush(); }
+
+ let mut hasher = Md5::new();
+ write!(&mut buf, "{i}");
+ hasher.update(buf.as_slice());
+ let hash = hasher.finalize();
+ if hash.starts_with(&[0, 0]) && hash[2] < 16 {
+ let mut hexhash = String::with_capacity(32);
+ for digit in hash {
+ write!(&mut hexhash, "{digit:02x}");
+ }
+ println!("Got 5 digit hash: {hexhash}, at {i}");
+ break;
+ }
+ buf.truncate(INPUT.len());
+ }
+
+ for i in 0.. {
+ if i % 1000 == 0 { print!("{i}\r"); std::io::stdout().flush(); }
+
+ let mut hasher = Md5::new();
+ write!(&mut buf, "{i}");
+ hasher.update(buf.as_slice());
+ let hash = hasher.finalize();
+ if hash.starts_with(&[0, 0, 0]) {
+ let mut hexhash = String::with_capacity(32);
+ for digit in hash {
+ write!(&mut hexhash, "{digit:02x}");
+ }
+ println!("Got 6 digit hash: {hexhash}, at {i}");
+ break;
+ }
+ buf.truncate(INPUT.len());
+ }
+}