Skip to content

Instantly share code, notes, and snippets.

@arialdomartini
Last active May 3, 2018 20:03
Show Gist options
  • Save arialdomartini/968d6f1872e9c90b1f72f039498cdd0e to your computer and use it in GitHub Desktop.
Save arialdomartini/968d6f1872e9c90b1f72f039498cdd0e to your computer and use it in GitHub Desktop.
indice che divide una lista in due liste con somme uguali
(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