Advertisement
Guest User

Untitled

a guest
Jun 6th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 0.82 KB | None | 0 0
  1. (define (foldr f a list)
  2.   (cond((null? list) a)
  3.        (#t (f (car list) (foldr f a (cdr list)))) ))
  4.  
  5.  
  6.  
  7. (define (sum ls)
  8.   (foldr (lambda (x y) (+ x y)) 0 ls))
  9.  
  10. (define (sameSum? ls tfls)
  11.   (let* ((sum1 (getList #t ls tfls))
  12.          (sum2 (getList #f ls tfls)))
  13.     (= sum1 sum2)))
  14.  
  15. (define (getList tf ls idls)
  16.   (let* ((identifiedls (map (lambda (x y) (if (equal? y tf) x 0)) ls idls)))
  17.     (sum identifiedls)))
  18.  
  19. (define (canSplit? ls)
  20.   (let* ((len (length ls)))
  21.      
  22.     (define (generate totalLen curLs choice origls)
  23.       (cond ((= totalLen (length curLs)) (sameSum? origls curLs))
  24.             ((generate totalLen (cons (car choice) curLs) choice origls) #t)
  25.             ((generate totalLen (cons (cadr choice) curLs) choice origls) #t)
  26.             (else #f)))
  27.     (generate len '() '(#t #f) ls)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement