add chapter 1 ex1

This commit is contained in:
Juthatip McDevitt 2025-07-26 14:06:23 -05:00
parent a6988e484d
commit 449b6ae825

33
chapter_1/ex_1.rkt Normal file
View file

@ -0,0 +1,33 @@
#lang sicp
10 ;result 10
(+ 5 4 3) ;5+4+3=12
(- 9 1) ;9-1=8
(/ 6 2) ;6/2=3
(+ (* 2 4) (- 4 6)) ;(2*4) + (4-6)=6
(define a 3)
(define b (+ a 1))
(+ a b (* a b)) ;a is 3, b is a+1 which is 3+1 4 so that a+b+(a*b) that is 3+4+(3*4)=19
(= a b) ;a is 3 and b is 4 the result is false
(if (and (> b a) (< b (* a b)))
b
a) ;it is true that b>a --> (4>3) it is not true that (< b (* a b)) --> (4 > 12) so that b and a = 4
(cond ((= a 4) 6)
((= b 4) (+ 6 7 a))
(else 25)) ;a=4 = false, b=4 = true so that 6+7+3 = 16
(+ 2 (if (> b a) b a)) ; b>a is true so that 2+4 = 6
(* (cond ((> a b) a)
((< a b) b)
(else -1))
(+ a 1)) ;a>b is false, a<b is true, (+a 1) --> (3+1)=4 which is 4*4 = 16