Last active
March 20, 2025 04:47
-
-
Save newmen/d628f5ed80a7eb0e303453b7a0024506 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(import '[java.math MathContext RoundingMode]) | |
(comment | |
(apply + (last | |
(transpose | |
(map (fn [i] | |
(concat (repeat i 0) | |
(map (partial * 1.75) (range 1 (- 12 i))))) | |
(range 11))))) | |
) | |
(defn bd-round | |
([bd] | |
(bd-round bd 2)) | |
([bd accuracy] | |
(bd-round bd accuracy RoundingMode/HALF_EVEN)) | |
([bd accuracy mode] | |
(if (bd? bd) | |
(.stripTrailingZeros (.setScale bd accuracy mode)) | |
bd))) | |
(defn bd? | |
[x] | |
(instance? BigDecimal x)) | |
(defn- bd-if-not | |
[x] | |
(if (bd? x) | |
x | |
(BigDecimal. x))) | |
(defn divide | |
([a b] | |
(let [a' (bd-if-not a) | |
b' (bd-if-not b)] | |
(.stripTrailingZeros (.divide a' b' MathContext/DECIMAL32)))) | |
([a b & tail] | |
(reduce (fn [acc x] | |
(divide acc x)) | |
(divide a b) | |
tail))) | |
(def ydays | |
[31 28 31 30 31 30 31 31 30 31 30 31]) | |
(defn get-sec | |
[x] | |
(mapcat (fn [n] | |
(cons x (repeat (dec n) 0))) | |
ydays)) | |
(comment | |
(let [start 6300000 | |
secs (get-sec 240000)] | |
(bd-round (* (- 1 0.15M) | |
(- (reduce (fn [acc x] | |
(+ x | |
(bd-round (* acc (+ 1 (divide 19.5M 100 365))) 2))) | |
start | |
secs) | |
(+ start (apply + secs)))) | |
2)) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment