Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
44
Task/ABC-problem/Cowgol/abc-problem.cowgol
Normal file
44
Task/ABC-problem/Cowgol/abc-problem.cowgol
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
include "cowgol.coh";
|
||||
include "strings.coh";
|
||||
|
||||
sub can_make_word(word: [uint8]): (r: uint8) is
|
||||
var blocks: [uint8] := "BOXKDQCPNAGTRETGQDFSJWHUVIANOBERFSLYPCZM";
|
||||
|
||||
# Initialize blocks array
|
||||
var avl: uint8[41];
|
||||
CopyString(blocks, &avl[0]);
|
||||
|
||||
r := 1;
|
||||
loop
|
||||
var letter := [word];
|
||||
word := @next word;
|
||||
if letter == 0 then break; end if;
|
||||
|
||||
# find current letter in blocks
|
||||
var i: @indexof avl := 0;
|
||||
loop
|
||||
var block := avl[i];
|
||||
if block == 0 then
|
||||
# no block, this word cannot be formed
|
||||
r := 0;
|
||||
return;
|
||||
elseif block == letter then
|
||||
# we found it, blank it out
|
||||
avl[i] := ' ';
|
||||
avl[i^1] := ' '; # and the other letter on the block too
|
||||
break;
|
||||
end if;
|
||||
i := i + 1;
|
||||
end loop;
|
||||
end loop;
|
||||
end sub;
|
||||
|
||||
# test a list of words
|
||||
var words: [uint8][] := {"A","BARK","BOOK","TREAT","COMMON","SQUAD","CONFUSE"};
|
||||
var resp: [uint8][] := {": No\n", ": Yes\n"};
|
||||
var i: @indexof words := 0;
|
||||
while i < @sizeof words loop
|
||||
print(words[i]);
|
||||
print(resp[can_make_word(words[i])]);
|
||||
i := i + 1;
|
||||
end loop;
|
||||
Loading…
Add table
Add a link
Reference in a new issue