Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (define (foldr f a list)
- (cond((null? list) a)
- (#t (f (car list) (foldr f a (cdr list)))) ))
- (define (sum ls)
- (foldr (lambda (x y) (+ x y)) 0 ls))
- (define (sameSum? ls tfls)
- (let* ((sum1 (getList #t ls tfls))
- (sum2 (getList #f ls tfls)))
- (= sum1 sum2)))
- (define (getList tf ls idls)
- (let* ((identifiedls (map (lambda (x y) (if (equal? y tf) x 0)) ls idls)))
- (sum identifiedls)))
- (define (canSplit? ls)
- (let* ((len (length ls)))
- (define (generate totalLen curLs choice origls)
- (cond ((= totalLen (length curLs)) (sameSum? origls curLs))
- ((generate totalLen (cons (car choice) curLs) choice origls) #t)
- ((generate totalLen (cons (cadr choice) curLs) choice origls) #t)
- (else #f)))
- (generate len '() '(#t #f) ls)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement