Created
July 25, 2015 08:37
-
-
Save cocodrips/ada8749d67cb04dc531c to your computer and use it in GitHub Desktop.
SRM663 Div1 Easy
This file contains hidden or 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
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