; Copyright (C) 2014 by Alexandru Cojocaru ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . (use-modules (ice-9 rdelim)) (define t) (define names) (define lambdas) (define (lam i) (list-ref lambdas (- i 1))) (define (c D i) (let l ((j 1) (p 1)) (if (> j D) p (if (= j i) (l (+ j 1) p) (l (+ j 1) (* p (/ (lam j) (- (lam j) (lam i))))))))) (define (mysum D t) (let l ((i 1) (s 0)) (if (> i D) s (l (+ i 1) (+ s (* (lam i) (c D i) (exp (- (* (lam i) t))))))))) (define (N D t) (* (/ 100.0 (lam D)) (mysum D t))) (define (parse) (set! t (string->number (read-line))) (read-line) (let l ((lams '()) (ns '())) (let ((ln (string-split (read-line) (char-set #\space #\:)))) (let ((ns (cons (list-ref ln 0) ns)) (lams (cons (string->number (list-ref ln 2)) lams))) (if (= (car lams) 0) (begin (set-car! lams 0.00000000000001) ; hack to avoid division by 0.0 (set! lambdas (reverse! lams)) (set! names (reverse! ns))) (l lams ns)))))) (parse) (let ((D (length lambdas))) (let l ((i 1)) (unless (> i D) (display (list-ref names (- i 1))) (display ": ") (display (N i t)) (display "%") (newline) (l (+ i 1)))))