Skip to content

Instantly share code, notes, and snippets.

@ejamesc
Created April 28, 2015 15:37
Show Gist options
  • Save ejamesc/ef14947dda07aa24a8f9 to your computer and use it in GitHub Desktop.
Save ejamesc/ef14947dda07aa24a8f9 to your computer and use it in GitHub Desktop.
def replace(s, casey)
a = s
case casey
when 1
a.sub("AB", "AA")
when 2
a.sub("BA", "AA")
when 3
a.sub("CB", "CC")
when 4
a.sub("BC", "CC")
when 5
a.sub("AA", "A")
when 6
a.sub("CC", "C")
end
end
def solution(s)
funcs = (1..6).to_a
cont = true
while cont do
count = 1
for i in funcs
s2 = replace(s, i)
count = count + 1
if s2 != s
puts s2
puts i
funcs.delete(i)
s = s2
break
end
if count == funcs.length
cont = false
break
end
end
s
end
end
puts solution("ABBCC")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment