Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help with SICP

Name: Anonymous 2008-01-06 22:44

http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-10.html#%_sec_1.1.6
Exercise 1.3 is a bitch. I think I'm close to a solution, then I see a fundamental flaw, and have to rewrite it. My notebook paper hurts.

Name: Anonymous 2008-01-06 23:40

lolwut? There are exactly three cases. Use a cond structure to cover them. In b4 ``clever'' trickwankery.

Name: Anonymous 2008-01-07 0:02

(define (square x) (* x x))

(define (sum-of-squares x y)
  (+ (square x) (square y)))

(define (square-largest x y z)
  (cond (or (> x y) (> x z)) (if (and (> x y) (> x z)) (define a x) (define b x))
    (or (> y x) (> y z)) (if (and (> y x) (> y z)) (define a y) (define b y))
    (else (if (and (> z x) (> z y)) (define a z) (define b z))))
  (sum-of-squares a b))


This is what I have.

Name: Anonymous 2008-01-07 0:05

(define (square x) (* x x))

(define (sum-of-squares x y)
  (+ (square x) (square y)))

(define (square-largest x y z)
  (cond (or (> x y) (> x z)) (if (and (> x y) (> x z)) (define a x) (define b x))
    (or (> y x) (> y z)) (if (and (> y x) (> y z)) (define a y) (define b y))
    (else (if (and (> z x) (> z y)) (define a z) (define b z))))
  (sum-of-squares a b))


This is what I have (And know is wrong).

Name: Anonymous 2008-01-07 0:22

>>3
Valid perl cod

Name: Anonymous 2008-01-07 0:54

>>2
Actually, there's 13 cases:
x > y > z
x > z > y
y > x > z
y > z > x
z > x > y
z > y > x
(x = y) > z
(x = y) < z
(x = z) > y
(x = z) < y
(y = z) > x
(y = z) < x
x = y = z

Name: Anonymous 2008-01-07 1:15

>>6
Actually, there are exactly three cases relevant to the exercise.

Name: Anonymous 2008-01-07 2:36

Sage for toy language faggotry. Please keep this shit off /prog/ thanks.

Name: Anonymous 2008-01-07 4:17

>>8
Sage for noob faggotry. Please keep this shit off /prog/ thanks.

Name: Anonymous 2008-01-07 6:29

You guys should think simpler. If the procedure operates on the two higher values and there's three values, then it's easier to just check for the low value and operate on the other two.

Name: Anonymous 2008-01-07 7:55

>>4

How many cons have you just left there, for the garbage collector to feed upon?
 
I feel kind of bad about it :(

Name: Anonymous 2008-01-07 8:08

sad japanese is sad :(

Name: Anonymous 2008-01-07 10:03

(define (exercise-1.3 a b c)
  ((lambda (x y)
     (+ (* x x) (* y y)))
   (max a b)
   (max (min a b) c)))

Name: Anonymous 2008-01-07 10:12

I'd foldr your max, if you know what I mean.

Name: Anonymous 2008-01-07 10:50

How many cons have you just left there, for the garbage collector to feed upon?
 
I feel kind of bad about it :(

Name: Anonymous 2008-01-07 11:45

>>15
>>11
(define *conses* '()) ; Global list to store keep-alive references to cons.
(define (better-cons x y) ; Please replace all instances of cons with better-cons.
  (let ((m (cons x y)))
    (set! *conses* (better-cons m *conses*))
    m))

Name: Anonymous 2008-01-07 11:59

>>10
IFLY
I
Fucking
Love
You

Name: Anonymous 2008-01-07 12:09

OP here, with the newfound simplicity in this exercise, I can change my code to

define (square x) (* x x))

(define (sum-of-squares x y)
  (+ (square x) (square y)))

(define (square-largest x y z)
  (cond (and (< x y) (< x z)) (define a y) (define b z)
    (and (< y x) (< y z)) (define a x) (define b z)
    (else (define a x) (define b y)))
  (sum-of-squares a b))

Name: Anonymous 2008-01-07 12:13

>>18
I MISSED A PAREN

Name: Anonymous 2008-01-07 19:11


<?php
function faggot(){$a=func_get_args();@array_pop(rsort($a));return(int)($a[0]*$a[0])+($a[1]*$a[1]);}
echo faggot(7,5,3)
?>


Someone post a worse solution.

Name: Anonymous 2008-01-07 19:12

>>20
Accidental sage lol

Name: Anonymous 2008-01-07 21:34

>>18
That only works if all the numbers are different.

Name: Anonymous 2008-01-08 0:19

>>22
Think, motherfucker, think.

Name: Anonymous 2008-01-08 12:58

>>22
But I could fix that o:

Name: Anonymous 2008-03-20 22:32

How many cons have you just left there, for the garbage collector to feed upon?
 
I feel kind of bad about it :(

Name: Anonymous 2009-03-18 3:18

The word pirahna, is all I can think of that rhymes with marijuana

Marijuana MUST be legalized.

Name: Anonymous 2011-02-02 23:23


Don't change these.
Name: Email:
Entire Thread Thread List