Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/ABC-problem/Python/abc-problem-2.py
Normal file
25
Task/ABC-problem/Python/abc-problem-2.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
BLOCKS = 'BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM'.split()
|
||||
|
||||
def _abc(word, blocks):
|
||||
for i, ch in enumerate(word):
|
||||
for blk in (b for b in blocks if ch in b):
|
||||
whatsleft = word[i + 1:]
|
||||
blksleft = blocks[:]
|
||||
blksleft.remove(blk)
|
||||
if not whatsleft:
|
||||
return True, blksleft
|
||||
if not blksleft:
|
||||
return False, blksleft
|
||||
ans, blksleft = _abc(whatsleft, blksleft)
|
||||
if ans:
|
||||
return ans, blksleft
|
||||
else:
|
||||
break
|
||||
return False, blocks
|
||||
|
||||
def abc(word, blocks=BLOCKS):
|
||||
return _abc(word.upper(), blocks)[0]
|
||||
|
||||
if __name__ == '__main__':
|
||||
for word in [''] + 'A BARK BoOK TrEAT COmMoN SQUAD conFUsE'.split():
|
||||
print('Can we spell %9r? %r' % (word, abc(word)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue