Commit 693638c7 authored by epsi sayidina's avatar epsi sayidina

PPh ps 17: Tarif Progresif

parent b6db7902
-- pemula haskell
import Data.Foldable
-- penghasilan kena pajak
pkps :: [Int]
pkps = [0, 50*10^6, 250*10^6, 500*10^6, 10^9]
......@@ -9,13 +6,14 @@ pkps = [0, 50*10^6, 250*10^6, 500*10^6, 10^9]
pph :: Int -> Int
pph pkp = round $ pph_recursive $ fromIntegral pkp
where
pph_recursive 0 = 0
pph_recursive pkp_real = (pkp_real - tm) * p + pph_recursive(tm)
-- [(tingkat, persentase)]
reff = [(0, 5), (50, 15), (250, 25), (500, 30)]
reff2 = [ (t*(10^6), (p/100)) | (t, p) <- reff]
pph_recursive 0 = 0
pph_recursive pkp_real =
(\(t, p) -> (pkp_real - t) * p + pph_recursive(t)) tariff
where
-- [(tingkat, persentase)]
reff = [(0, 0.05), (50, 0.15), (250, 0.25), (500, 0.30)]
indices = [ i | (i, (t, p)) <- zip [0..] reff, pkp_real > t * (10^6)]
(t, p) = (reff !! last indices)
tm = t * (10^6)
indices = [ i | (i, (t, p)) <- zip [0..] reff2, pkp_real > t]
tariff = reff2 !! last indices
main = forM_ pkps (print . pph)
main = mapM_ (print . pph) pkps
......@@ -9,11 +9,12 @@ pph :: Int -> Int
pph pkp = round $ pph_recursive $ fromIntegral pkp
where
[t1, t2, t3, t4] = map (* 10^6) [0, 50, 250, 500]
[p1, p2, p3, p4] = [0.05, 0.15, 0.25, 0.30]
pph_recursive pkp_real
| pkp_real > t4 = (pkp_real - t4) * 0.30 + pph_recursive t4
| pkp_real > t3 = (pkp_real - t3) * 0.25 + pph_recursive t3
| pkp_real > t2 = (pkp_real - t2) * 0.15 + pph_recursive t2
| pkp_real > t1 = (pkp_real - t1) * 0.05 + pph_recursive t1
| pkp_real > t4 = (pkp_real - t4) * p4 + pph_recursive t4
| pkp_real > t3 = (pkp_real - t3) * p3 + pph_recursive t3
| pkp_real > t2 = (pkp_real - t2) * p2 + pph_recursive t2
| pkp_real > t1 = (pkp_real - t1) * p1 + pph_recursive t1
| otherwise = 0
main = forM_ pkps (print . pph)
......@@ -9,15 +9,13 @@ pkps = [0, 50*10^6, 250*10^6, 500*10^6, 10^9]
pph :: Int -> Int
pph pkp = round $ pph_recursive $ fromIntegral pkp
where
pph_recursive pkp_real = pkp_guard pkp_real
pph_recursive 0 = 0
pph_recursive pkp_real = (pkp_real - tm) * p + pph_recursive(tm)
where
pkp_guard pkp_real
| pkp_real == 0 = 0
| otherwise = (pkp_real - tm) * p + pph_recursive(tm)
-- [(tingkat, persentase, pengurang)]
reff = [(0, 0.05), (50, 0.15), (250, 0.25), (500, 0.30)]
indices = [ i | (i, (t, p)) <- zip [0..] reff, pkp_real > t * (10^6)]
(t, p) = (reff !! last indices)
tm = t * (10^6)
-- [(tingkat, persentase)]
reff = [(0, 0.05), (50, 0.15), (250, 0.25), (500, 0.30)]
indices = [ i | (i, (t, p)) <- zip [0..] reff, pkp_real > t * (10^6)]
(t, p) = (reff !! last indices)
tm = t * (10^6)
main = forM_ pkps (print . pph)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment