Skip to content

Instantly share code, notes, and snippets.

@jonelf
Created February 8, 2015 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonelf/d6228b4e95482c637312 to your computer and use it in GitHub Desktop.
Save jonelf/d6228b4e95482c637312 to your computer and use it in GitHub Desktop.
Avkodar Rövarspråket i Ruby
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
@jonelf
Copy link
Author

jonelf commented Feb 8, 2015

=> "vattenkokare"

@jonelf
Copy link
Author

jonelf commented Feb 12, 2015

@jonelf
Copy link
Author

jonelf commented Jun 21, 2018

'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