Problem In this assignment, you are going to write a Scheme program that finds the correct movements in a path. Figure 1
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Problem In this assignment, you are going to write a Scheme program that finds the correct movements in a path. Figure 1
Tasks In Scheme, a path will be represented in the form of a linked-list. Figure 2 shows how the path in Figure 1 is represented in terms of a linked list in Scheme. Starting cell [0,0] has the letter S, the finishing cell has the letter F and empty cells have the letter E. The walls have the letter - (minus). 0 1 2 3 4 0 s 1 E - 2 E E E E F 3 TI - E 4 Figure 2 - Linked List representation of the path shown in Figure 1 The following function "buildPath" on the left is given for you which takes a list of lists and creates a path (grid) using the lists. You can use this function to create different paths in order to test your code. On the right the code shows how the path in Figure 2 is created. (define (buildPath rows) (cond ((null? rows) null) (else (cons (build-path (cdr rows) ) (car rows))))) (define sample-path (build-path "("S" "-" "_" "_" "_") "_" "_" "_" "_") ("E" "E" "E" "E" "E") "E") "-" "-" "E")))) Scheme code for creating a path Scheme code of the sample path in Figure 2
Task 1: Define two functions "getHeight" and "getwidth" which takes a path as an input and returns the height and the width of the path. (getHeight sample-path) → should return 5 (getwidth sample-path) →should return 5 Task 2: Define a function "getLetter" which takes a path, a row number and a column number. Then it returns the letter from the path on the corresponding location [row, column] (getLetter sample-path 0 0) → should return S (getLetter sample-path 1 0) →should return E (getLetter sample-path 1 1) → should return - (getLetter sample-path 4 4) → should return F Task 3: Define a function "solve Path" which takes a path and returns the solution for the path. (solve Path sample-path) →should return (D DRRRRD D)