Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Created July 25, 2015 08:37
Show Gist options
  • Save cocodrips/ada8749d67cb04dc531c to your computer and use it in GitHub Desktop.
Save cocodrips/ada8749d67cb04dc531c to your computer and use it in GitHub Desktop.
SRM663 Div1 Easy
class ABBADiv1:
def canObtain(self, initial, target):
def f(initial, rev, target):
if len(target) == len(initial):
return initial == target
if initial in target or rev in target:
if (target[-1] == 'A'):
if f(initial, rev, target[:-1]):
return True
if (target[0] == 'B'):
t = target[1:]
if f(initial, rev, t[::-1]):
return True
return False
rev = initial[::-1]
if f(initial, rev, target):
return "Possible"
return "Impossible"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment