Created
February 8, 2015 14:40
-
-
Save jonelf/d6228b4e95482c637312 to your computer and use it in GitHub Desktop.
Avkodar Rövarspråket i Ruby
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
require 'set' | |
swedish_consonants = "bcdfghjklmnpqrstvwxz".chars.to_set | |
code = "vovatottotenonkokokokarore".chars | |
result = [code.first] | |
i = 1 | |
while (i < code.length) | |
if code[i] == "o" && code[i-1] == code[i+1] && swedish_consonants.include?(code[i-1]) | |
code[i+1] = "☃" # So that second o in kokokok is parsed correctly. | |
i += 2 | |
else | |
result << code[i] | |
i += 1 | |
end | |
end | |
result.join |
'rorövovarorsospoproråkoketot'.gsub(/([bcdfghjklmnpqrstvxz])o\1/, '\1')
'kalle blomkvist'.gsub(/([bcdfghjklmnpqrstvxz])/, '\1o\1')
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
=> "vattenkokare"