Mark, You have 2 equations, so you can solve them to the same variable: a+b = $a_plus_b a/b = $a_divided_by_b
so a = b * $a_divided_by_b and b * $a_divided_by_b + b = $a_plus_b and b * ($a_divided_by_b + 1) = $a_plus_b and b = $a_plus_b/($a_divided_by_b + 1) which you can solve given your input values, then plug the calculated b value back into a = b * $a_divided_by_b to get a. Rick -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Mark Knoop Sent: Wednesday, September 26, 2007 6:51 AM To: [email protected] Subject: Re: How to resolve a and b when one knows the sum and the dividend > Say we know that > > a + b = $a_plus_b > > and > > a/b = 0.5 > > then of course > > a = 20, b = 40 > > which you can see by common sense or by plotting two lines on a graph. > > But how to do this programmatically so that it works for any input values > (without attempting some way of running through possible values and > testing)? > > use strict; > use warnings; > my $a_plus_b = 60; > my $a_divided_by_b = 0.5; > my ($a, $b) = resolve_a_b($a_plus_b, $a_divided_by_b); > print "a = $a , b = $b\n"; > > sub resolve_a_b { > my $a_plus_b = shift; > my $a_divided_by_b = shift; > my ($a,$b); > ### what goes here? > return ($a, $b); > } > >From the response I got from one list member I have ended up with: use strict; use warnings; my $a_plus_b = 60; my $a_divided_by_b = 1.5; my ($a, $b) = resolve_a_b($a_plus_b, $a_divided_by_b); print "a = $a , b = $b\n"; sub resolve_a_b { my $a_plus_b = shift; my $a_divided_by_b = shift; my ($a,$b); $b = $a_plus_b/($a_divided_by_b + 1); $a = $a_plus_b - $b; return ($a, $b); } which works for any input values. Whether or not this solves my cropping problem or not is another matter! Thanks Mark _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
