diff options
| author | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
|---|---|---|
| committer | Gaspard Coulet <gaspard.coulet@mines-ales.org> | 2021-04-28 23:05:53 +0200 |
| commit | 9fe033ea88c2f705ec18c232873d056e0c229d72 (patch) | |
| tree | 0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_4/progaapp/TP1/tp1.rkt | |
Initial commit
Diffstat (limited to 'sem_4/progaapp/TP1/tp1.rkt')
| -rw-r--r-- | sem_4/progaapp/TP1/tp1.rkt | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/sem_4/progaapp/TP1/tp1.rkt b/sem_4/progaapp/TP1/tp1.rkt new file mode 100644 index 0000000..bb92134 --- /dev/null +++ b/sem_4/progaapp/TP1/tp1.rkt @@ -0,0 +1,111 @@ +;Gaspard Coulet, 21601609 Groupe B + +#lang racket +(define exo9 (lambda (t) (if (and ( >= t -3) (<= t -1)) 1 (if (and (>= t 2) (<= t 4)) 2 0)))) + + +(define bissextile + (lambda (x) + ( if (= (modulo x 4) 0) + (if (not (= ( modulo x 100) 0)) + #t + (if (= ( modulo x 400) 0) + #t + #f) + ) + #f) + ) + ) + +(define nb-annee-bissextile + (lambda (x) + (letrec ( (f + (lambda (x i) + (if (not (= x 1900)) + (if (bissextile x) + (f (- x 1) (+ i 1)) + (f (- x 1) i) + ) + i) + ) + )) + ( f x 0) + ) + ) + ) + +(define nb-jours-au-1-jan + (lambda (x) + (letrec ((f + (lambda (x i) + (if (not(= x 1)) + (if (or (= 2 x) (= x 4) (= x 6) (= x 9) (= x 11)) + (if (= x 2) + (f (- x 1) ( + i 28)) + (f (- x 1) (+ i 30)) + ) + (f (- x 1) (+ i 31)) + ) + ( + i 31) + ) + ) + )) + (if (= 1 x) + 0 + ( f (- x 1) 0) + ) + ) + ) + ) + +(define nb-jours (lambda (m d y) + (let ((i (if (= y 1900) + 0 + (+ (* (nb-annee-bissextile y) 1) (* 365 (- y 1900))) + ) + )) + (let ((i (+ i (nb-jours-au-1-jan m)))) + (let ((i (+ i d))) + (- i 1) + ) + ) + ) + ) + ) + +(define jour-semaine (lambda (m d y) + (let ((nbjour (nb-jours m d y))) + (if (= (modulo nbjour 7) 0) + (display "Lundi") + (if (= (modulo nbjour 7) 1) + (display "Mardi") + (if (= (modulo nbjour 7) 2) + (display "Mercredi") + (if (= (modulo nbjour 7) 3) + (display "Jeudi") + (if (= (modulo nbjour 7) 4) + (display "Vendredi") + (if (= (modulo nbjour 7) 5) + (display "Samedi") + (if (= (modulo nbjour 7) 6) + (display "Dimanche") + (display "étrange") + ) + + ) + ) + ) + ) + ) + ) + ) + ) + ) + +;Question devoir TP1 : +; Exercice 1 : +; (map exo9 '(-5 -4 -3 -2 -1 0 1 2 3 4 5)) +; Exercice 2 : +; (bissextile 1408) +; (bissextile 1500) +; (jour-semaine 1 13 2408) |
