Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Mad-Libs/Racket/mad-libs.rkt
Normal file
28
Task/Mad-Libs/Racket/mad-libs.rkt
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
(define (get-mad-libs file)
|
||||
(with-input-from-file file
|
||||
(lambda ()
|
||||
(for/fold ((text ""))
|
||||
((line (in-lines)))
|
||||
(string-append text line "\n")))))
|
||||
|
||||
|
||||
(define (replace-context mad-libs)
|
||||
(define matches
|
||||
(regexp-match* #rx"<[a-zA-Z0-9 ]*>" mad-libs))
|
||||
(map
|
||||
(lambda (context)
|
||||
(display (format "~a?" context))
|
||||
(cons context (read-line)))
|
||||
(remove-duplicates matches)))
|
||||
|
||||
(define (play-mad-libs)
|
||||
(display "Tell me a file to play Mad Libs: ")
|
||||
(define text (get-mad-libs (read-line)))
|
||||
(define matches (replace-context text))
|
||||
|
||||
(display
|
||||
(for/fold ((mad-story text))
|
||||
((change (in-list matches)))
|
||||
(string-replace mad-story (car change) (cdr change)))))
|
||||
|
||||
(play-mad-libs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue