0

This is my first attempt at Scheme & I seem to be stuck at the end of the line. This program is to take a list of numbers, two-subsets and pull numbers that equal the same sum. ie; 5 + 2 = 7 and 4 + 3 = 7. The program should print the two subsets {5 2} {4 3} I am receiving an error "else: not allowed as an expression" and I just can't seem to understand why. Any hints or direction is appreciated.

(define two-subsets (lambda (list count sum1 sum2)
    (cond ((and (not (= count 0) (= sum1) (= sum2) #t)
    ((null? list) #f)
    ((two-subsets (cdr list) (+ count) (+ sum1) (+ sum2 (car list) #t)
    ((two-subsets (cdr list) (+ count 1) (- sum1) (- sum2 (car list) #t)
    (else (two-subsets (cdr list) count sum1 sum2)))
))))
wackyred
  • 1
  • 1
  • After looking at your code for less than 10 seconds, I'm willing to bet that some indentation--specifically, some drracket auto-indent--would help you understand this problem. Also, the stepper might be quite helpful as well. – John Clements Apr 29 '17 at 17:59
  • In fact, as pasted, this thing doesn't have matching parens at all. Did something go wrong in the copy-paste? – John Clements Apr 29 '17 at 18:00
  • Thank you John! Your suggestions have put me on the right track. I wish I could blame the copy & paste for my parenthesis. Moreover, it is simply not knowing what I am doing & that brackets are not allowed in this version of Racket. – wackyred Apr 29 '17 at 23:54

0 Answers0