47 lines
1.6 KiB
Plaintext
47 lines
1.6 KiB
Plaintext
class Abc {
|
|
function : Main(args : String[]) ~ Nil {
|
|
blocks := ["BO", "XK", "DQ", "CP", "NA",
|
|
"GT", "RE", "TG", "QD", "FS",
|
|
"JW", "HU", "VI", "AN", "OB",
|
|
"ER", "FS", "LY", "PC", "ZM"];
|
|
|
|
IO.Console->Print("\"\": ")->PrintLine(CanMakeWord("", blocks));
|
|
IO.Console->Print("A: ")->PrintLine(CanMakeWord("A", blocks));
|
|
IO.Console->Print("BARK: ")->PrintLine(CanMakeWord("BARK", blocks));
|
|
IO.Console->Print("book: ")->PrintLine(CanMakeWord("book", blocks));
|
|
IO.Console->Print("treat: ")->PrintLine(CanMakeWord("treat", blocks));
|
|
IO.Console->Print("COMMON: ")->PrintLine(CanMakeWord("COMMON", blocks));
|
|
IO.Console->Print("SQuAd: ")->PrintLine(CanMakeWord("SQuAd", blocks));
|
|
IO.Console->Print("CONFUSE: ")->PrintLine(CanMakeWord("CONFUSE", blocks));
|
|
}
|
|
|
|
function : CanMakeWord(word : String, blocks : String[]) ~ Bool {
|
|
if(word->Size() = 0) {
|
|
return true;
|
|
};
|
|
|
|
c := word->Get(0)->ToUpper();
|
|
for(i := 0; i < blocks->Size(); i++;) {
|
|
b := blocks[i];
|
|
if(<>(b->Get(0)->ToUpper() <> c & b->Get(1)->ToUpper() <> c)) {
|
|
Swap(0, i, blocks);
|
|
new_word := word->SubString(1, word->Size() - 1);
|
|
new_blocks := String->New[blocks->Size() - 1];
|
|
Runtime->Copy(new_blocks, 0, blocks, 1, blocks->Size() - 1);
|
|
if(CanMakeWord(new_word, new_blocks)) {
|
|
return true;
|
|
};
|
|
Swap(0, i, blocks);
|
|
};
|
|
};
|
|
|
|
return false;
|
|
}
|
|
|
|
function : native : Swap(i : Int, j : Int, arr : String[]) ~ Nil {
|
|
tmp := arr[i];
|
|
arr[i] := arr[j];
|
|
arr[j] := tmp;
|
|
}
|
|
}
|