Data update
This commit is contained in:
parent
52a6ef48dd
commit
157b70a810
604 changed files with 14253 additions and 2100 deletions
|
|
@ -1,21 +1,14 @@
|
|||
# ABC problem: #
|
||||
# determine whether we can spell words with a set of blocks #
|
||||
|
||||
# construct the list of blocks #
|
||||
[][]STRING blocks = ( ( "B", "O" ), ( "X", "K" ), ( "D", "Q" ), ( "C", "P" )
|
||||
, ( "N", "A" ), ( "G", "T" ), ( "R", "E" ), ( "T", "G" )
|
||||
, ( "Q", "D" ), ( "F", "S" ), ( "J", "W" ), ( "H", "U" )
|
||||
, ( "V", "I" ), ( "A", "N" ), ( "O", "B" ), ( "E", "R" )
|
||||
, ( "F", "S" ), ( "L", "Y" ), ( "P", "C" ), ( "Z", "M" )
|
||||
);
|
||||
|
||||
# Returns TRUE if we can spell the word using the blocks, FALSE otherwise #
|
||||
# Returns TRUE for an empty string #
|
||||
PROC can spell = ( STRING word, [][]STRING blocks )BOOL:
|
||||
PROC can spell = ( STRING word, [][]STRING block set )BOOL:
|
||||
BEGIN
|
||||
|
||||
# construct a set of flags to indicate whether the blocks are used #
|
||||
# or not #
|
||||
[ 1 LWB blocks : 1 UPB blocks ]BOOL used;
|
||||
[ 1 LWB block set : 1 UPB block set ]BOOL used;
|
||||
FOR block pos FROM LWB used TO UPB used
|
||||
DO
|
||||
used[ block pos ] := FALSE
|
||||
|
|
@ -34,11 +27,11 @@ PROC can spell = ( STRING word, [][]STRING blocks )BOOL:
|
|||
|
||||
# look through the unused blocks for the current letter #
|
||||
BOOL found := FALSE;
|
||||
FOR block pos FROM 1 LWB blocks TO 1 UPB blocks
|
||||
FOR block pos FROM 1 LWB block set TO 1 UPB block set
|
||||
WHILE NOT found
|
||||
DO
|
||||
IF ( c = blocks[ block pos ][ 1 ][ 1 ]
|
||||
OR c = blocks[ block pos ][ 2 ][ 1 ]
|
||||
IF ( c = block set[ block pos ][ 1 ][ 1 ]
|
||||
OR c = block set[ block pos ][ 2 ][ 1 ]
|
||||
)
|
||||
AND NOT used[ block pos ]
|
||||
THEN
|
||||
|
|
@ -56,25 +49,33 @@ PROC can spell = ( STRING word, [][]STRING blocks )BOOL:
|
|||
END; # can spell #
|
||||
|
||||
|
||||
main: (
|
||||
# main # (
|
||||
|
||||
[][]STRING abc blocks # construct the list of blocks #
|
||||
= ( ( "B", "O" ), ( "X", "K" ), ( "D", "Q" ), ( "C", "P" )
|
||||
, ( "N", "A" ), ( "G", "T" ), ( "R", "E" ), ( "T", "G" )
|
||||
, ( "Q", "D" ), ( "F", "S" ), ( "J", "W" ), ( "H", "U" )
|
||||
, ( "V", "I" ), ( "A", "N" ), ( "O", "B" ), ( "E", "R" )
|
||||
, ( "F", "S" ), ( "L", "Y" ), ( "P", "C" ), ( "Z", "M" )
|
||||
);
|
||||
|
||||
# test the can spell procedure #
|
||||
PROC test can spell = ( STRING word, [][]STRING blocks )VOID:
|
||||
PROC test can spell = ( STRING word, [][]STRING block set )VOID:
|
||||
write( ( ( "can spell: """
|
||||
+ word
|
||||
+ """ -> "
|
||||
+ IF can spell( word, blocks ) THEN "yes" ELSE "no" FI
|
||||
+ IF can spell( word, block set ) THEN "yes" ELSE "no" FI
|
||||
)
|
||||
, newline
|
||||
)
|
||||
);
|
||||
|
||||
test can spell( "A", blocks );
|
||||
test can spell( "BaRK", blocks );
|
||||
test can spell( "BOOK", blocks );
|
||||
test can spell( "TREAT", blocks );
|
||||
test can spell( "COMMON", blocks );
|
||||
test can spell( "SQUAD", blocks );
|
||||
test can spell( "CONFUSE", blocks )
|
||||
test can spell( "A", abc blocks );
|
||||
test can spell( "BaRK", abc blocks );
|
||||
test can spell( "BOOK", abc blocks );
|
||||
test can spell( "TREAT", abc blocks );
|
||||
test can spell( "COMMON", abc blocks );
|
||||
test can spell( "SQUAD", abc blocks );
|
||||
test can spell( "CONFUSE", abc blocks )
|
||||
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue