-
Notifications
You must be signed in to change notification settings - Fork 68
/
AlienAccent.rb
37 lines (30 loc) · 1.09 KB
/
AlienAccent.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
=begin
Aliens from Kepler 27b have immigrated to Earth! They have learned English and
go to our stores, eat our food, dress like us, ride Ubers, use Google, etc.
However, they speak English a little differently. Can you write a program that
converts their Alien English to our English?
Task:
Write a function converting their speech to ours. They tend to speak the letter
a like o and o like a u. NOTE: There is an issue with this kata when it is solved
in python 2x. The issue turned out to be easy to fix but there is a bug in the
re-publishing system preventing the kata from being updated. The issue has been
posted on Github.
>>> convert('hello')
'hellu'
>>> convert('codewars')
'cudewors'
=end
# My Solution
def convert2(st)
st.tr('o','u').tr('a','o')
end
words = ['apple', 'banana', 'cucumber', 'donkey', 'elephant',
'fox', 'gorilla', 'hummus', 'igloo', 'joke', 'lemon',
'monkey', 'no']
(1..200).each do |rtest|
st = []
(2..rand(50)).each {|x| st << words[rand(words.length)]}
st = st.join(" ")
solution = convert2(st)
Test.assert_equals(convert(st),solution,"Expected: '#{solution}'")
end