Last active
February 10, 2019 00:39
-
-
Save agumonkey/cf5820a842d3280079c471c8d40de089 to your computer and use it in GitHub Desktop.
calcul les impots par tranche (fr_FR)
This file contains 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
;; -*- lexical-binding: t -*- | |
(require 'dash) | |
;; (setq lexical-binding t) | |
;; from: https://impots.dispofi.fr/bareme-impot/calcul-impot-par-tranche | |
;; De 0€ à 9964€ 0% | |
;; De 9964€ à 27519€ 14% | |
;; De 27519€ à 73779€ 30% | |
;; De 73779€ à 156244€ 41% | |
;; De 156244€ à +oo 45% | |
(defvar *tranches* '((0 9964 0) | |
(9964 27519 14) | |
(27519 73779 30) | |
(73779 156244 41) | |
(156244 1000000000000 45)) | |
"tranches d'imposition") | |
(defun in (v l h) (and (< l v) (< v h))) | |
;;- (in 10 0 100) | |
(defun crimp (v l h) | |
;; v l h -> ? | |
;; l v h -> v - l | |
;; l h v -> h | |
(cond ((< v l) v) | |
((> v h) h) | |
(t (- v l)))) | |
;;- (crimp 24000 9000 28000) | |
(defun inter (v l h) | |
;; v l h -> v | |
;; l v h -> v - l | |
;; l h v -> h - l | |
(cond ((< v l) v) | |
((> v h) (- h l)) | |
(t (- v l)))) | |
;; (-map (-lambda ((s l h p)) (cons (crimp s l h) p)) | |
;; (-filter (-lambda ((s l h p)) (> s l)) | |
;; (-zip (-cycle '(24000)) *tranches*))) | |
;; (defun -impots (s ts) | |
;; (-map (-lambda ((s l h p)) (cons (crimp s l h) p)) | |
;; (-filter (-lambda ((s l h p)) (> s l)) | |
;; (-zip (-cycle (list s)) ts)))) | |
(defun -impots (s ts) | |
(-map (-lambda ((s l h p)) (cons (inter s l h) p)) | |
(-filter (-lambda ((s l h p)) (> s l)) | |
(-zip (-cycle (list s)) ts)))) | |
;;; (-impots 40000 *tranches*) | |
;;- (impots 24000 *tranches*) | |
;;- (impots 40000 *tranches*) | |
;;- ((9964 . 0) | |
;;- (27519 . 14) | |
;;- (12481 . 30)) | |
;;; (apply #'+ (mapcar #'car (-impots 40000 *tranches*))) | |
;; ((9964 . 0) | |
;; (27519 . 14) | |
;; (12481 . 30)) | |
(defun impots (s) | |
(let ((slices (-impots s *tranches*))) | |
(-reduce-from (-lambda (a (s . p)) (+ (/ (* s p) 100) a)) 0 slices))) | |
(impots 40000) | |
;; 6201 | |
(let* ((r 40000) | |
(i (impots r))) | |
(list :percent (* (/ (float i) r) 100) | |
:ratio (/ r (float i)))) | |
;; (:percent 15.5025 :ratio 6.450572488308337) | |
;; (:percent 18.990000000000002 :ratio 5.265929436545551) | |
(message "done.") | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; REST | |
(defun then (f g) | |
(lambda (v) | |
(funcall f v) | |
(funcall g v))) | |
(defmacro fn (&rest body) | |
`(lambda () ,@body)) | |
(global-set-key (kbd "C-c C-b") (then #'eval-buffer (fn (message "done.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment