| about | help | code help+videos | done | prefs |
scrabble_legal_play
In a series of exercises we will develop a program to find the highest-scoring play on a Scrabble board. But we'll get there in small steps. In this exercise, we will decide if it is legal to play a given word at a given start position on a Scrabble board. To make things easier, in these first few exercises, the board will consist of a single row, which will be represented as a list: a 1 indicates a blank square (later we will add 2, 3, etc. for double-and triple letter scores), a '*' marks the start square at the center of the board, and a capital letter indicates a letter already on the board. Write scrabble_legal_play(row, k, word) to return True if it is legal to play the word in the row, starting at position k. A word is legal at a position k if (1) the word does not go off the edge of the board; (2) the word does not bump into any other letters at the end (that is, if you want to place the word 'CAT' on the board '...DOG....', it is ok to place it like this: '...DOG.CAT' but not ok like this: 'CATDOG....'); (3) the letters already on the board match up with the letters in the word; (4) the word connects to at least one existing letter on the board, or it covers the start square, '*'. scrabble_legal_play([1, 1, 1, 1, 'O', 1, 1, 1], 0, 'HELLO') → True scrabble_legal_play([1, 'E', 1, 1, 'O', 1, 1, 1], 0, 'HELLO') → True scrabble_legal_play([1, 'A', 1, 1, 'O', 1, 1, 1], 0, 'HELLO') → False ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 470 Post-solution available
Copyright Nick Parlante 2017 - privacy