Skip to content

Instantly share code, notes, and snippets.

@danott
Created March 26, 2015 16:31
Show Gist options
  • Save danott/a1a3cbd8d0b1f7176266 to your computer and use it in GitHub Desktop.
Save danott/a1a3cbd8d0b1f7176266 to your computer and use it in GitHub Desktop.
Randomize the digits, uniq for each line of each run.
#!/usr/bin/env ruby
s = gets
while s
map_old_to_new = {}
available_digits = %w(0 1 2 3 4 5 6 7 8 9)
(0..9).each do |old|
new = available_digits.sample
available_digits -= [new]
map_old_to_new["#{old}"] = new
end
puts s.gsub(/\d/) { |old| map_old_to_new[old] }
s = gets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment