From 5058285c728a83ea6f1c20de1ea0aa9b9cb13dfb Mon Sep 17 00:00:00 2001 From: mehbark Date: Thu, 14 Nov 2024 00:31:51 -0500 Subject: [PATCH] poem_loop --- Cargo.lock | 46 ++++++++++++++++++++ Cargo.toml | 1 + extract_poems.rb | 19 ++++++++ poem_loop.rb | 52 ++++++++++++++++++++++ src/main.rs | 111 ++++++++++++++++++++++++++--------------------- 5 files changed, 180 insertions(+), 49 deletions(-) create mode 100644 extract_poems.rb create mode 100644 poem_loop.rb diff --git a/Cargo.lock b/Cargo.lock index a7cdf07..88e46c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,6 +26,31 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crypto-common" version = "0.1.6" @@ -82,9 +107,30 @@ name = "pearls" version = "0.1.0" dependencies = [ "itertools", + "rayon", "sha2", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "sha2" version = "0.10.8" diff --git a/Cargo.toml b/Cargo.toml index 8559881..8153aeb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,4 +5,5 @@ edition = "2021" [dependencies] itertools = "0.13.0" +rayon = "1.10.0" sha2 = "0.10.8" diff --git a/extract_poems.rb b/extract_poems.rb new file mode 100644 index 0000000..d19bacc --- /dev/null +++ b/extract_poems.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +MIN_8S = 0 + +def max_8s(str) + (str.scan(/8+/).max || '').length +end + +$stdin.read.split('poem: ') + .map(&:strip) + .reject(&:empty?) + .to_set + .map { [_1, `printf "#{_1}" | openssl sha256`.strip] } + .filter { |(_, hash)| max_8s(hash) >= MIN_8S } + .sort_by { |(_, hash)| max_8s hash } + .each do |(amulet, hash)| + puts amulet + puts "#{max_8s hash} #{hash}#{amulet.length > 64 ? ' too long!' : ''}" + end diff --git a/poem_loop.rb b/poem_loop.rb new file mode 100644 index 0000000..d30bb9e --- /dev/null +++ b/poem_loop.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +LLAMA_PATH = "#{Dir.home}/Downloads/Meta-Llama-3-8B-Instruct.Q5_K_M.llamafile" + +PROMPT = <<~END_OF_PROMPT + poem: If you can't write poems, + write me + + poem: IN THE SPRING MY LUNGS + STILL SOMEHOW EXPAND. + + poem: A MAN ONCE MAILED ME + A PIECE OF HIS HEART + + poem: THIS AMULET + AT ANY PRICE + FELT LIKE THE TRUTH + + poem: this amulet is a simple token which proves my love's truth + + poem: sphinx of black quartz, judge my vow + + poem: DON'T WORRY. + + poem: in the early hours of the new year + i lie on my back + waiting. + + poem: All my life I had this + image of what a poet + should be + + poem: Winter evening, a leaf, a blue sky above. + + poem: Lethargically good. + + poem: +END_OF_PROMPT + .strip + +def doit! + r, w = IO.pipe + spawn("#{LLAMA_PATH} --no-display-prompt --gpu APPLE -n 128 -p \"#{PROMPT}\"", out: w, err: '/dev/null') + spawn('ruby extract_poems.rb', in: r) + Process.wait + # just in case + r.close + w.close +end + +doit! +doit! diff --git a/src/main.rs b/src/main.rs index 32586ef..8c51f4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,11 @@ +use std::process::exit; + use itertools::Itertools; +use rayon::prelude::*; use sha2::{Digest, Sha256}; // we could be smart with prefixes +#[allow(clippy::too_many_lines)] fn main() { let choices = [ vec![ @@ -40,47 +44,47 @@ fn main() { vec!["this sentence", "this message", "this piece of digitext"], vec![" has "], vec![ - "seven", - "7", - "7 (seven)", - "seven (7)", - "7!", - "7(!)", - "seven!", - "seven(!)", - "7!!", - "7(!!)", - "seven!!", - "seven(!!)", - "7!!!", - "7(!!!)", - "seven!!!", - "seven(!!!)", - "7!!!!!!!", - "7(!!!!!!!)", - "seven!!!!!!!", - "seven(!!!!!!!)", + "ten", + "10", + "10 (ten)", + "ten (10)", + "10!", + "10(!)", + "ten!", + "ten(!)", + "10!!", + "10(!!)", + "ten!!", + "ten(!!)", + "10!!!", + "10(!!!)", + "ten!!!", + "ten(!!!)", + "10!!!!!!!!!!", + "10(!!!!!!!!!!)", + "ten!!!!!!!!!!", + "ten(!!!!!!!!!!)", ], vec![" "], vec![ - "7s", - "sevens", - "7s!", - "7s(!)", - "sevens!", - "sevens(!)", - "7s!!", - "7s(!!)", - "sevens!!", - "sevens(!!)", - "7s!!!", - "7s(!!!)", - "sevens!!!", - "sevens(!!!)", - "7s!!!!!!!", - "7s(!!!!!!!)", - "sevens!!!!!!!", - "sevens(!!!!!!!)", + "0s", + "zeroes", + "0s!", + "0s(!)", + "zeroes!", + "zeroes(!)", + "0s!!", + "0s(!!)", + "zeroes!!", + "zeroes(!!)", + "0s!!!", + "0s(!!!)", + "zeroes!!!", + "zeroes(!!!)", + "0s!!!!!!!!!!", + "0s(!!!!!!!!!!)", + "zeroes!!!!!!!!!!", + "zeroes(!!!!!!!!!!)", ], vec![" "], vec![ @@ -101,16 +105,25 @@ fn main() { vec![" "], vec!["somewhat ", "pretty ", "quite ", "very ", "decently ", ""], vec!["fun", "nice", "sweet", "pleasant", "cool", "interesting"], + vec![" "], + vec![ + ":)", ":D", ":))", ":)))", "XD", ":B", ">:)", ">:D", ">XD", ">:B", "B)", "BD", ">B)", + ">BD", "(:", "((:", "(((:", "(:<", + ], ]; - for selection in choices.into_iter().multi_cartesian_product() { - let mut hasher = Sha256::new(); - for choice in &selection { - hasher.update(choice); - } - let digest = hasher.finalize(); - if format!("{digest:x}").contains("7777777") { - println!("{}", selection.join("")); - println!("{digest:x}"); - } - } + choices + .into_iter() + .multi_cartesian_product() + .par_bridge() + .for_each(|selection| { + let mut hasher = Sha256::new(); + for choice in &selection { + hasher.update(choice); + } + let digest = hasher.finalize(); + if format!("{digest:x}").contains("0000000000") { + println!("{}\n{digest:x}", selection.join("")); + exit(0); + } + }); }