tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
24
Task/Permutation-test/Common-Lisp/permutation-test-1.lisp
Normal file
24
Task/Permutation-test/Common-Lisp/permutation-test-1.lisp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
(defun perm-test (s1 s2)
|
||||
(let ((more 0) (leq 0)
|
||||
(all-data (append s1 s2))
|
||||
(thresh (apply #'+ s1)))
|
||||
(labels
|
||||
((recur (data sum need avail)
|
||||
(cond ((zerop need) (if (>= sum thresh)
|
||||
(incf more)
|
||||
(incf leq)))
|
||||
((>= avail need)
|
||||
(recur (cdr data) sum need (1- avail))
|
||||
(recur (cdr data) (+ sum (car data)) (1- need) (1- avail))))))
|
||||
|
||||
(recur all-data 0 (length s1) (length all-data))
|
||||
(cons more leq))))
|
||||
|
||||
(let* ((a (perm-test '(68 41 10 49 16 65 32 92 28 98)
|
||||
'(85 88 75 66 25 29 83 39 97)))
|
||||
(x (car a))
|
||||
(y (cdr a))
|
||||
(s (+ x y)))
|
||||
(format t "<=: ~a ~6f%~% >: ~a ~6f%~%"
|
||||
x (* 100e0 (/ x s))
|
||||
y (* 100e0 (/ y s))))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<=: 80551 87.197%
|
||||
>: 11827 12.803%
|
||||
Loading…
Add table
Add a link
Reference in a new issue