@ Pohon BBS

SICP : Let's Read!

Go back: thread mode | tree mode | sub tree

#14. Excercise 1.3
Published: 2026-09-09 [Wed] 01:43, by PhatCat
My attempt at exercise 1.3. it took me a long time as most of my attempts made code that excluded anything that wasn't the maximum number, so i guess finding the "middle" number is what makes this challenging. my first attempts were checking each variable against the others individually (mistake). if x>y then output x otherwise 0, if x>z output x otherwise 0 then multiply both outputs, repeat for each variable (rather silly in retrospect). After this i decided to only compare to the third variable if the first check failed and directly compute the square if the variable wasn't the minimum. Code below:

#lang sicp
(define (sicp_ex_1.3 x y z)
(+
(if (< x y) (if (< x z) 0 (* x x)) (* x x))
(if (< y x) (if (< y z) 0 (* y y)) (* y y))
(if (< z y) (if (< z x) 0 (* z z)) (* z z))))

(sicp_ex_1.3 1 2 3)
result was 13 so it worked
.

New Reply



(new)

You need to solve the captcha before you can post.


Parents

#13. exercise 1.3
Published: 2026-09-08 [Tue] 21:50, by piper
(define (square x)
(* x x))
(define (sum-squares x y)
(+ (square x) (square y)))

(define (sum-greater-squares x y z)
(if (> x y)
(if (> y z)
(sum-squares x y)
(sum-squares x z))
(if (> x z)
(sum-squares y x)
(sum-squares y z))))

(sum-greater-squares 1 2 3)
(sum-greater-squares 4 2 3)
(sum-greater-squares 5 1 0)
.

#4. Chapter 1
Published: 2026-09-08 [Tue] 19:21, by Anonymous
SICP chapter 1
> Building Abstractions with Procedures

https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-9.html#%_chap_1
.

#1. SICP : Let's Read!
Published: 2026-09-08 [Tue] 19:18, by piper
> SICP Book:
https://mitp-content-server.mit.edu/books/content/sectbyfn/books_pres_0/6515/sicp.zip/full-text/book/book-Z-H-4.html

> SICP Lectures:
https://www.youtube.com/playlist?list=PLE18841CABEA24090
> Racket Scheme
https://racket-lang.org/download/
> SICP Racket
https://docs.racket-lang.org/sicp-manual/Installation.html

Let's embrace the tree structure of Pohon BBS.

Top level comments for chapters of the book,
replies to top level comments for discussions of the chapter.

Comment #2 will be for general help installing Scheme
Comment #3 will be for random Scheme discussion that doesn't
fit into chapter discussion.

Ready, start, go!
.
Pohon BBS