-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw5-problem1.rkt
93 lines (63 loc) · 3.58 KB
/
hw5-problem1.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname hw5-main) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Problem 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; You are going to make yourself a useful interactive app: flash cards
; (https://en.wikipedia.org/wiki/Flashcard).
; To begin, consider the following data definition...
(define-struct flashcard [front back])
; A FlashCard is a (make-flashcard String String)
; Interpretation: the front and back of a card
; TODO 1/4: Complete the design recipe for FlashCard.
; Now a single flash card wouldn't be super useful, and so...
; TODO 2/4: Design ListOfFlashCard (LoFC) to support an arbitrarily sized
; sequence of flash cards. Importantly...
; - These should be proper lists (i.e., using cons and '()).
; - Make sure to give yourself a few example lists, of different sizes;
; hopefully they are useful in your classes!
; - Remember that your LoFC template should reflect that your list
; elements are themselves designed types (FlashCard).
; Now, for practice...
; TODO 3/4: Design the function has-text?, which determines if a list of flash
; cards contains any card that contains a supplied text.
;
; Hint: the string-contains? function is very useful for determining
; if one string contains another :)
; Finally, let's put this list to use :)
; TODO 4/4: Design the program go-cards, which helps you study with a supplied list
; of cards. It starts on the first card and then flips it when a key is
; pressed, and then goes to the front of the next card when another key is
; pressed. The program should end when the last card has been flipped, and
; the go-cards function should return how many cards were in the original
; list. Some hints...
; - To get you started, you have been supplied the data definition of a
; way to represent the state of the program (don't forget to uncomment
; the structure definition and finish the design recipe for data!).
; - The return value of this function is a bit challenging, since the list
; you get at the end is empty! So uncomment the code we've given you below,
; but to understand: you can *add* the length of the originally supplied
; list to that of the (empty) final list and still get the right answer :)
; - Be sure to follow the templates for all your data, which will typically
; entail helpers for the FS, the LoFC, and the FC.
; - As long as the program operates as described, you are welcome to make it
; look as simple or as creative as you would like - we hope it helps you
; in your classes!! :)
; (define-struct fs [cards front?])
; A FlashState (FS) is a (make-fs LoFC Boolean)
; Interpretation: a list of cards, and whether
; the front is face up
; go-cards : LoFC -> Nat
; displays the cards in sequence (flip via key),
; returning the number of cards
#|
(define (go-cards lofc)
(+
(length lofc)
(length (fs-cards
(big-bang (make-fs lofc #t)
[to-draw draw-fs]
[on-key flip-fs]
[stop-when done-fs?])))))
|#