Skip to content

Instantly share code, notes, and snippets.

@nerdinand
Last active November 7, 2021 15:33
Show Gist options
  • Save nerdinand/d56ad39196171f7553d0fd079ab7fed9 to your computer and use it in GitHub Desktop.
Save nerdinand/d56ad39196171f7553d0fd079ab7fed9 to your computer and use it in GitHub Desktop.
#!/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