Hello,
Je débute en Scheme, et pour mon premier programme -un 'MasterMind'- je n'arrive pas à trouver la bonne structure, le bon découpage - aussi au niveau de l'indentation.
J'ai essayé plein de commandes mais je suis à peu près que se sont les moins pertinents .
Je n'arrive pas non plus à comprendre la différence entre 'and' et 'and?', alors que se sont tous les 2 des prédicats, je crois ?
Et de même pour 'not' et 'not?' ?
Merci pour votre aide !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #lang racket ;; Master Mind ;; (define nC 8) (define lType [list nC nC nC nC]) (define nMyst (map (lambda (n) (random n)) lType)) (define (ask) (let* ([i (read [current-input-port])]) (if (and (integer? i) (>= i 0) (< i nC)) i (begin [printf "You must write a number between 0 and ~a\n" (- nC 1)] (ask))) ) ) (define (L L1) (let* ([ans (list (ask) (ask) (ask) (ask))]) (list (map [lambda (a b) (if (equal? a b) 'T [if [ormap equal? (list a a a a) L1] 'B 'F])] ans L1) ans) ) ) (do ([nT 0 (+ nT 1)] [iList (L nMyst) (append (L nMyst) iList)]) ((equal? (second iList) nMyst) (printf "You win: ~a !!" nMyst)) (begin (printf "Round n°~a, \nF => False \nB => Bad Position \nT => True \nIt is incorrect: \n" nT) (for-each (lambda (arg) (printf "~a\n" arg)) iList) ) )
Partager