Skip to content

Instantly share code, notes, and snippets.

@agumonkey
Last active February 10, 2019 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agumonkey/cf5820a842d3280079c471c8d40de089 to your computer and use it in GitHub Desktop.
Save agumonkey/cf5820a842d3280079c471c8d40de089 to your computer and use it in GitHub Desktop.
calcul les impots par tranche (fr_FR)
;; -*- 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