Created
July 9, 2012 00:53
-
-
Save pebbie/3073646 to your computer and use it in GitHub Desktop.
solusi http://tokilearning.org/problem/221 Tetangga Bidang Persegi
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
tetangga = { | |
"1": {"R":"2","D":"3"}, | |
"2": {"L":"1","D":"4"}, | |
"3": {"R":"4","U":"1"}, | |
"4": {"L":"3","U":"2"} | |
} | |
def getND(kode,arah): | |
if arah in tetangga[kode[-1]]: | |
return kode[:-1]+tetangga[kode[-1]][arah] | |
else: | |
return getND(kode[:-1], arah) | |
if __name__=='__main__': | |
k = '413' | |
print getND(k,'L') | |
print getND(k,'U') | |
print getND(k,'R') | |
print getND(k,'D') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment