amulets/extract_poems.rb
2024-11-14 00:31:51 -05:00

20 lines
484 B
Ruby

# 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