2017-09-23 10:01:46 +02:00
|
|
|
from strutils import toUpperAscii, contains, format
|
2016-12-05 23:44:36 +01:00
|
|
|
from sequtils import delete
|
|
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
proc makeWord(s: string): bool =
|
2016-12-05 23:44:36 +01:00
|
|
|
var
|
|
|
|
|
abcs = @["BO", "XK", "DQ", "CP", "NA", "GT", "RE", "TG", "QD", "FS",
|
|
|
|
|
"JW", "HU", "VI", "AN", "OB", "ER", "FS", "LY", "PC", "ZM"]
|
|
|
|
|
|
|
|
|
|
if s.len > abcs.len:
|
|
|
|
|
return false
|
|
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
for ch in s.toUpperAscii.items:
|
|
|
|
|
block outer:
|
|
|
|
|
for i, abc in abcs.pairs:
|
|
|
|
|
if abc.contains(ch):
|
|
|
|
|
abcs.delete(i)
|
|
|
|
|
break outer
|
|
|
|
|
return false
|
|
|
|
|
return true
|
2016-12-05 23:44:36 +01:00
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
let words = @["A", "bArK", "BOOK", "treat", "common", "sQuAd", "CONFUSE"]
|
2016-12-05 23:44:36 +01:00
|
|
|
for word in words:
|
2017-09-23 10:01:46 +02:00
|
|
|
echo format("""Can the blocks make the word "$1"? $2 """, word,
|
|
|
|
|
if makeWord(word): "yes" else: "no")
|