Created
July 13, 2021 14:20
-
-
Save peterc/72c5759f903e8b2ce1fb08226c66f2d4 to your computer and use it in GitHub Desktop.
Convert abbreviated text like i18n and l11n to full text
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
text = ARGV.first || "y1u a5t p1l? j2t w4d to s1y hi" | |
times = (ARGV[1] || 1).to_i | |
words = File.readlines('/usr/share/dict/words') | |
.map(&:downcase) | |
.map(&:chomp) | |
times.times do | |
puts text.gsub(/\w+/) { |word| | |
words.select { |realword| | |
realword.start_with?(word[0]) && | |
realword.end_with?(word[-1]) && | |
realword.length == word[1..-2].to_i + 2 | |
}.sample | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment