Last active
November 7, 2021 15:33
-
-
Save nerdinand/d56ad39196171f7553d0fd079ab7fed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
NAMES = %w{ | |
Heinz | |
Ina | |
Ferdinand | |
Konstantin | |
Kaspar | |
Katalin | |
Leonie | |
} | |
def tainted?(associations) | |
return true if associations.size == 0 | |
assoc = associations.dup | |
assoc.keep_if { |k, v| k == v } | |
assoc.size > 0 | |
end | |
associations = {} | |
passes = 0 | |
while tainted?(associations) | |
bowl = NAMES.dup | |
NAMES.each do |name| | |
associations[name] = bowl.shuffle!.shift | |
end | |
passes += 1 | |
end | |
system 'clear' | |
puts "Lösung gefunden nach #{passes} Versuchen." | |
associations.each do |key, value| | |
File.write "#{key}.txt", value + ' ' * (NAMES.sort_by(&:length).last.length - value.length) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment