Advertisement
Guest User

Untitled

a guest
Feb 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. def convert(chr)
  2. chr = chr.upcase
  3. # subtract "A"
  4. n = (chr.ord - 65) / 3
  5. # account for #7 & #9 which have 4 chars
  6. n -= 1 if chr == "S".freeze || chr == "V".freeze || chr >= "Y".freeze
  7. (n + 2).to_s
  8. end
  9.  
  10. puts "180044STERN".gsub(/[a-z]/i) { |chr| convert(chr) }
  11. puts "555AXYZ".gsub(/[a-z]/i) { |chr| convert(chr) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement