@ Pohon BBS
SICP : Let's Read! (18 replies)

■ 🕑 16. fix ex 1.3
│  summed all 3 squares if x y z were the same. added a check to just force one variable to zero if all the numbers were equal so theres probably a more elegant solution :P. Code:
│  
│  #lang sicp
│  
│  (define (square x) (* x x))
│  
│  (define (sicp_ex_1.3 x y z)
│   (+
│   (if (= x y) 0 (if (= x z) 0
│   (if (< x y) (if (< x z) 0 (square x)) (square x))))
│   (if (< y x) (if (< y z) 0 (square y)) (square y))
│   (if (< z y) (if (< z x) 0 (square z)) (square z))))
│  
│  (sicp_ex_1.3 1 2 3)
│  (sicp_ex_1.3 2 2 2)
│  (sicp_ex_1.3 2 1 0)
│   
└─■ 🕑 17. epic phail
    Fixed the fix
    
    #lang sicp
    
    (define (square x) (* x x))
    
    (define (sicp_ex_1.3 x y z)
     (+
     (if (= x y z) 0
     (if (< x y) (if (< x z) 0 (square x)) (square x))))
     (if (< y x) (if (< y z) 0 (square y)) (square y))
     (if (< z y) (if (< z x) 0 (square z)) (square z)))
    
    (sicp_ex_1.3 1 2 3)
    (sicp_ex_1.3 2 2 2)
    (sicp_ex_1.3 2 1 0)
     

Pohon BBS