```On Nov 7, 11:06=A0am, Mike Cargal <m... / cargal.net> wrote:
> On Nov 6, 2010, at 7:00 PM, flebber wrote:
>
>
>
>
>
>
>
>
>
> > On Nov 7, 9:45 am, flebber <flebber.c... / gmail.com> wrote:
> >> On Nov 7, 2:24 am, Robert Klemme <shortcut... / googlemail.com> wrote:
>
> >>> On 06.11.2010 10:19, flebber wrote:
>
> >>>> I am trying to create a class. I am struggling to figure the best fl=
ow
> >>>> to get the maths side to work.
>
> >>>> So say that
>
> >>>> R is a float given by user input
> >>>> P is a Total amount(Pool)
> >>>> Per is a variable %
> >>>> X is a variable that is a percentage of P defined by a maximum
> >>>> allocation.
>
> >>>> So main =3D (( R * X)/P)*100
>
> >>> First of all you should get your variables right. =A0Variable "Per" d=
oes
> >>> not show up in the formula and "main" is not mentioned in the list.
>
> >>> The meaning of the formula is totally unclear to me. =A0From what you=
gave
> >>> you are calculating the fraction (R/P) multiply it with 100 (so you
> >>> actually get (R/P) percent and now you multiply with another percenta=
ge
> >>> (X). =A0So you have a percentage of a percentage.
>
> >>>> What I want to test is the value of X needed to equal Per from X's
> >>>> maximum allocation down.
>
> >>> Can you write down a formula that contains all variables in your list
> >>> and point at the fixed ones (constants), user inputs and variables yo=
u
> >>> want to resolve?
>
> >>>> What i am thinking but cant get right
>
> >>>> Say
>
> >>>> R =3D 5
> >>>> P =3D 10
> >>>> Per =3D 190
> >>>> X =3D max 80% of P
>
> >>>> For X in main =3D Per ( Closest whole number or half that equals clo=
sest
> >>>> to but greater than Per)
> >>>> main =3D (( 5 * 8)/10)*100
>
> >>>> So in example intially main equalled 400%. And answer I would want t=
o
> >>>> resolve it to is X =3D 4 which is 200% as 3.50 equals 180%.
>
> >>>> Any ideas?
>
> >>> Sorry you lost me somewhere along the path. =A0Also it's tea time rig=
ht now...
>
> >>> Cheers
>
> >>> =A0 =A0 =A0 =A0 robert
>
> >>> --
> >>> remember.guy do |as, often| as.you_can - without endhttp://blog.rubyb=
estpractices.com/
>
> >> So I want to check by changing X when in forumla "main" that it is =3D=
>
> >> than "per"
>
> >> In simple terms I want to calculate units needed to reach a rate of
> >> return, X represents the variable units and per is the ROI(return of
> >> investment rate I would deaire to acheive), R is the ratio of return
> >> and P is a pool or base amount, I am using base 10 to start off with.
>
> >> I am trying to test X for a value, the only constraint on X is that it
> >> cannot exceed 80% of the P or Pool amount.
> >> So if I set per =3D 190%
>
> >> R =3D 5
> >> P =3D 10
> >> Per =3D 190
> >> X =3D max 80% of P
>
> >> For X in main >=3D per
>
> >> main =3D (( 5 * X)/10)*100 >=3D 190%
>
> >> so for X =3D 80% of P or 8 base units
>
> >> main =3D (( 5 * 8)/10)*100
>
> >> which would test out as
>
> >> main >=3D per
>
> >> 400 =3D> 190 -
>
> >> So when X is 8 units the main section is greater than per but its not
> >> the closest whole unit to per.
>
> >> So when X =3D 40% or 4 base units
>
> >> main =3D (( 5 * 4)/10)*100
> >> main >=3D per
> >> 200 >=3D 190
>
> >> this is the largest unit in 0.5 increments that remains greater than
> >> Per of 190 so I would want X once tested to resolve to this.
>
> >> I hope that made sense.
>
> > So how do I best get X to run a loop in 0.5 increments until it
> > reaches the closest value that makes the left side of an equation
> > greater or equal to the right. But where it is the lowest value that
> > is greater than or equal to the the right.
>
> > Main =3D> Per - where main is the lowest value it can be greater than
> > per.
>
> > Cheers
>
> > Sayth
>
> Something's not right with your formulas (I suspect)
>
> >>>> main =3D (( R * X)/P)*100
>
> and X =3D X*P
>
> so... main =3D =A0
> R*(X*P)
> ----------- * 100
> =A0 =A0 =A0 P =A0 =A0 =A0 =A0
>
> the P's cancel out...
> R*X*100
>
> varying P will not change the results of your calculations...
>
> here's what I believe that you're asking for...
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D
> r =3D 5.0
> p =3D 10.0
> per =3D 190.0
> x =3D 0.8
>
> begin
> =A0 =A0 =A0 =A0 main =3D ((r*(x*p))/p)*100 =A0
> =A0 =A0 =A0 =A0 lastSuccess =3D x if main >=3D per
> =A0 =A0 =A0 =A0 x -=3D 0.05
> end while main >=3D per
> puts "#{lastSuccess*100.0}%"
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
> note: you can change p al day long and always get the same answer
>
> there are probably more "rubified" ways to express this.
> I've tried to maintain the approach you've stated. =A0However, I would si=
mplify the equation first, and since the last X that succeeds as you decrem=
ent is the same thing as the first that succeeds as you're going up, I'd pr=
obably turn t into something like...
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
> r =3D 5.0
> p =3D 10.0
> per =3D 190.0
> max_x =3D 0.8
>
> x =3D 0.05
> const =3D r*100 # simplified without X
> x +=3D 0.05 while (x*const < per) && (x <=3D max_x)
> puts x <=3D max_x ? "#{lastSuccess*100.0}%" : "no answer"
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D
>
> Mike Cargal
>
> m... / cargal.nethttp://blog.mikecargal.com

Thanks for looking at this for me.

> You've really lost me when 80% turns into 8 (or 8 base units). =A0What is=
a base unit? And why would it be equal to 10%?
> Are you looking to vary X from 80% down by 5% increments?

This test is the first of 4 I plan to make into one program. For each
their while be a maximum allocation so in this case 80% so may be 40%
etc. The pool in future will vary but I am using base 10 while I write
it(hoping it would be clearer for another person reading it). So that
means that X has a max allocation of units if 40% was the maximum
allocation and base 10 then X would be 4 units and I would want my
loop to test X from 0 to 4 in 0.5 increments.

I am going to need more time to read your solution as I haven't got it
terators.html

and a solution flow similar to

ruby> def WHILE(cond)
|   return if not cond
|   yield
|   retry
| end
nil
ruby> i=3D0; WHILE(i<3) { print i; i+=3D1 }
012   nil

```