Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem set you will design a program for a crossword puzzle. A puzzle in this problem adheres to the following conditions - it

In this problem set you will design a program for a crossword puzzle.

A puzzle in this problem adheres to the following conditions - it is never empty - it is always square A word in a puzzle - can be found in the following dimensions: a row, a column, a diagonal or some combination of the three - CANNOT be backwards in any of these dimensions.

Design a function that consumes a word and a puzzle and produces true if the word is found in the puzzle and false otherwise. A word should be represented as a (listof 1String), where each element in the list is a letter in the word.

HINTS - think carefully about what the "problem" is and what the "next-problem" is when you are designing your function. Ask yourself, what is changing from one problem to the next. In triangle solitaire, the board changed from one problem to the next but, is the puzzle board changing in this problem? Work through an example problem on paper and identify the information that you are keeping track of when you are generating the next-problems.

- the width of a puzzle = square root of the number of letters in the puzzle - the position of the top left corner of the puzzle is (0,0) - the position of the bottom right corner of the puzzle is ((sub1 PUZZLE-WD), (sub1 PUZZLE-WD)) - a helper has been provided for you to get the letter-at a specified position in a given puzzle

The following are some examples to clarify the above text: ============================================================================ . ============================================================================ . ============================================================================ . ============================================================================

.

;; Constants ;; ================= (define COLD (list "C" "O" "L" "D")) (define COOKS (list "C" "O" "O" "K" "S")) (define POPS (list "P" "O" "P" "S")) (define COOL (list "C" "O" "O" "L")) (define HOT (list "H" "O" "T")) (define ROB (list "R" "O" "B")) (define ROPE (list "R" "O" "P" "E"))

;; Data Definitions ;; =================

;; Puzzle is (listof 1String) ;; interp. a square word search puzzle that's length >=1, ;; with each cell containing a single letter as a String ;; letters can spell words according to the following rules: ;; - downwards in a column ;; - left to right in a row ;; - on diagonal downwards, left to right ;; - some combination of the 3 above

(define P-1 (list "A")) (define P-5 (list "T" "C" "O" "L" "D" "C" "E" "P" "B" "Y" "O" "O" "K" "O" "X" "O" "D" "S" "R" "P" "L" "E" "Z" "X" "S"))

(define-struct pos (x y)) ;; Pos is (make-pos Integer Integer) ;; interp. an x, y position in the puzzle, where, ;; x is the column number and y is the row number in the Puzzle, ;; 0, 0 is upper left corner. ;; a position is only valid for a given Puzzle if: ;; - (<= 0 x (sub1 WD)) ;; - (<= 0 y (sub1 WD)) ;; where WD is the width of the Puzzle ;;

(define POS-ST (make-pos 0 0))

#; (define (fn-for-pos p) (... (pos-x p) (pos-y p)))

;; Functions ;; =================

;; (listof 1String) Puzzle -> Boolean ;; produce true if los is found in p, false otherwise

!!!!

(define (solveable? los puz) true) ;stub

;

;; Puzzle Pos -> 1String ;; produce the string at p in puz ;; ASSUME: p is within bounds of puz (check-expect (letter-at (list "a" "b" "c" "d") (make-pos 0 0)) "a") (check-expect (letter-at (list "a" "b" "c" "d") (make-pos 1 0)) "b") (check-expect (letter-at (list "a" "b" "c" "d") (make-pos 0 1)) "c") (check-expect (letter-at (list "a" "b" "c" "d" "e" "f" "g" "h" "i") (make-pos 2 2)) "i")

; template as call to list-ref (define (letter-at puz p) (local [(define WD (sqrt (length puz)))] (list-ref puz (+ (* (pos-y p) WD) (pos-x p)))))

please help me to fix functions

Using DrRacket

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions

Question

=+ Are they breakable for any reason?

Answered: 1 week ago

Question

=+When and under what circumstances are contracts renegotiated?

Answered: 1 week ago

Question

=+Are the contracts enforceable?

Answered: 1 week ago