0 Replies - 229 Views - Last Post: 09 December 2011 - 10:38 PM Rate Topic: -----

#1 jamesjonx01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 09-December 11

Scheme list sum

Posted 09 December 2011 - 10:38 PM

I am looking for a program in scheme that gives output 'true' if any sum of two numbers in list is equal to third number in the list. Else it gives 'false'.

Below is what I came up with:

(define Seq (lambda ( x1, x2, x3, S)
(cond
((null? S) 0)
((equal? x1 (car S)) (+ 1 (three x2 (cdr S))))
(else (three x3 (cdr S))))))

e.g. (three (3 8 13 5 19)) returns true because 8 = 3 + 5
If list has less than 3 digit, output is false.

Thank you.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1