Last active
May 3, 2018 20:03
-
-
Save arialdomartini/968d6f1872e9c90b1f72f039498cdd0e to your computer and use it in GitHub Desktop.
indice che divide una lista in due liste con somme uguali
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (mezzo-index ns) | |
(define sum | |
(lambda (l) | |
(if (null? l) | |
0 | |
(+ (car l) (sum (cdr l)))))) | |
(define (iter sn dx) | |
(cond ((null? dx) (length sn)) | |
((>= (sum sn) (sum dx)) (length sn)) | |
(else (iter (append sn (list (car dx))) | |
(cdr dx))))) | |
(iter () ns))) | |
(display (mezzo-index '(1 2 1 1 1 6))) | |
(newline) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment