anonymous

5 years ago

Some English words can be played on the keys of a piano, such as “face” or
“baggage”. A piano has keys named a, b, c, d, e, f, g.
Write a Scheme function can-play-word? that consumes a word (a non-empty
string) and produces true or false depending on whether the word can be played
on a piano or not. The only characters that can be played on a piano are lower case
letters. Some English words can be played on the keys of a piano, such as “face” or
“baggage”. A piano has keys named a, b, c, d, e, f, g.
Write a Scheme function can-play-word? that consumes a word (a non-empty
string) and produces true or false depending on whether the word can be played
on a piano or not. The only characters that can be played on a piano are lower case
letters. @Computer Science

I wrote a helper function can-play-letter? that determines if a single letter is playable. Then for can-play-word? I said it's either that the string is empty (base case), or the first letter is playable (do a little work) and the rest of the word is playable (recursively reduce it to a smaller problem).