Page 6: Solving a Word Puzzle
Unit 2, Lab 3, Page 6
Nobody would have to ask a computer “Does spaghetti have 5 letters?” The block should be retitled WORD ( ) HAS ( ) LETTERS so that it looks more sensible. –bh
Then chase the change forward into 5.1 starting on page 2, editing started files, solutions, and TG in both units as needed. –MF, 7/14/20
On this page, you will solve a crossword puzzle by combining predicates using the and
block. You will then use the resulting predicates with keep
to find words with specific characteristics.
-
You have used the block in the Operators palette together with
=
andkeep
to find words of a certain length in the words list.- Reassemble that script so that you can find all the words that have 8 letters.
- Find all the words that have 11 letters.
-
You now have an expression that you can edit to test any word for any number of letters. This is a useful tool to have. Create and test a predicate block that takes a word and number as input and works like this:
-
Build an expression using the block with
=
andkeep
to find words that have certain letters in certain places.- Use it to find all the words that begin with the letter i.
- Find all the words whose fourth letter is r.
-
If you have not yet turned your expression into a predicate block, do that now. Your block should work like this:
Your block’s title can be different from the one shown here as long as it does the same job.
-
Use your predicates, along with
and
andkeep
, to solve this Unit 2 Lab 3 Word Puzzle.To show your work, please make individual scripts for each word that you find. Place your scripts from top to bottom in the order that you found the words in. So, you are going to have multiple copies of similar scripts and change up what you are doing each time.
For example, this expression searches for 6 letter words that start with r and have d as the third letter:
All the words in the puzzle are related to the AP CS Principles course.
-
-
Create and test a predicate block that checks whether a certain letter is in a word. Examples below. Your block should:
- Accept two inputs: a letter to check for and a word, and
- Report whether or not the input word has the input letter.
-
Create this block:
The first input is a pattern, which is a word in which some of the letters have been replaced by hyphens (minus signs).