I found an interesting problem from here Mathologer - YouTube
So I decide to write a program to calculate the values based on the graphic solution provided by Mathologer. There was no algorithm in the video, so I have to invent one. After thtee fault solution I find how to "fill" like water the vessels of "claims", or pools (as objects)
I found that the objects has to be in ascending order, from smaller to higher claim, so the "water" split can be done faultless.
cls
Print "Talmudic bankruptcy problem"
report {
The Problem:
A man dies, leaving three creditors with claims of 100, 200, and 300. The estate's value is not specified, but the Talmud provides solutions for when the estate is worth 100, 200, and 300.
The Talmudic Solutions:
Estate Value of 100: The estate is divided equally, giving each creditor 33 1/3.
Estate Value of 200: The creditors receive 50, 75, and 75.
Estate Value of 300: The creditors receive 50, 100, and 150, proportional to their claims.
}
class pool {
claim as double
lim1 as value, total as value
function level(per_cent as double) {
if per_cent<.lim1 then
w=per_cent*.total
if w>=.claim/2 then
=.claim/2
else
=w
end if
else.if per_cent>1-.lim1 then
=.claim-per_cent*.total
else
=.claim
end if
}
module fix (t) {
.total<=t
.lim1<=.claim*2/t
}
class:
module pool (.claim) {
}
}
function total {
var tot as double
while not empty
read t as *pool
tot+=t=>claim
end while
=tot
}
function process(tot, estate) {
m=array([])
many=len(m)
k=each(m)
p=estate>tot/2
if p then estate=tot-estate
while k
t=array(k)
t=>fix tot
per_cent=estate/tot/many
z=t=>level(per_cent)
estate-=z
many--
if p then
data -round(z,2)+t=>claim
else
data round(z,2)
end if
end while
=array([])
}
a->pool(100)
b->pool(200)
c->pool(300)
total=total(a,b,c)
flush
data 50, 100, 200, 250, 275, 300, 400, 450, 500, 600
Pen 15 {Print "", " A", " B", " C", " SUM"}
while not empty
read that
rep=process(total, that, a, b, c)
Pen 15 {Print "estate = ";that,}
Print rep,
Pen 15 {Print round(rep#sum(),0)}
end while
total=total(a,b)
flush
data 50, 100, 200, 250, 275, 300
Pen 15{Print "", " A", " B","", " SUM"}
while not empty
read that
rep=process(total, that, a, b)
Pen 15 {Print "estate = ";that,}
Print rep," ....",
Pen 15 {Print round(rep#sum(),0)}
end while
Δεν υπάρχουν σχόλια:
Δημοσίευση σχολίου
You can feel free to write any suggestion, or idea on the subject.