-
-
Save djanatyn/54cd7bd330697e0dbc77 to your computer and use it in GitHub Desktop.
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
def rule_one string | |
return [string + "U"] if string[-1] == 'U' | |
return false | |
end | |
def rule_two string | |
return ["M" + (string[1..-1] * 2)] | |
end | |
def rule_three string | |
n = 2 | |
results = [] | |
while n <= string.length | |
new_string = string.clone | |
if new_string[(n-2)..n] =~ /III/ | |
new_string[(n-2)..n] = 'U' | |
results.push new_string | |
end | |
n += 1 | |
end | |
return results | |
end | |
def rule_four string | |
n = 1 | |
results = [] | |
while n <= string.length | |
new_string = string.clone | |
if new_string[(n-1)..n] =~ /UU/ | |
new_string[(n-1)..n] = '' | |
results.push new_string | |
end | |
n += 1 | |
end | |
return results | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment