Re: equivalent controls
- From: "Wade Ward" <wade@xxxxxxxxxxx>
- Date: Wed, 28 Nov 2007 21:21:41 -0700
"Jürgen Exner" <jurgenex@xxxxxxxxxxx> wrote in message
news:9Iq3j.17146$r81.5080@xxxxxxxxxxx
Wade Ward wrote:It sure looks like I'm torturing the syntax, but I got contract68 to work:
[...]
do {{[...]
$x_calc++;
$power++;
last if $x_calc > 10;
print STDOUT "x calc is $x_calc\n";
print STDOUT "x_calc out is $x_calc\n";
print STDOUT "power out is $power\n";
do {{
$power++;
$x_calc++;
print STDOUT "power in is $power\n";
print STDOUT "x_calc in is $x_calc\n";
$x_sought = $x_sought - 1;
last if 1 > 0;
print STDOUT "x sought is $x_sought\n";
}} until $x_calc > 7.5;
$x_calc = $penultimate;
}} until ($power > 6);
Is there a slicker way to do this in perl than using the double curly
braces?
Absolutely, here it goes for your main loop:
while ($power < 6 and $x_calc < 10) {
$x_calc++;
$power++;
print "x calc is $x_calc\n";
print "x_calc out is $x_calc\n";
print "power out is $power\n";
while ($x_calc <= 7.5 ){
$power++;
$x_calc++;
print "power in is $power\n";
print "x_calc in is $x_calc\n";
}
$x_calc = $penultimate;
};
It also reduced the number of lines from 20 to 14 and IMHO is much more
readable, too.
## contract68.pl
## one sided increasingly good guesses
## contributors: joe smith, jean luc, Jürgen Exner
use strict;
use warnings;
my $x_calc = 5.3;
my $x_sought = 7.321928094887362;
my $base = .5;
my $term = -.00057;
my $penultimate = -.00057;
my $cows_come_home = 0;
my $power = 1;
do {{
$term = $base**$power;
print STDOUT "term is $term \n";
print STDOUT "current is $penultimate \n";
$power++;
do {{
$penultimate = $x_calc;
$x_calc = $x_calc + $term;
# end inner do
# last if (10.0*(2.0**$x_calc) > 1600.0);
}} until (10.0*(2.0**$x_calc) > 1600.0);
$x_calc = $penultimate;
# end outer do
}} until ($power > 35);
$x_calc = $penultimate;
print STDOUT "x_calc output is $x_calc\n";
print STDOUT "x_sought output is $x_sought\n";
print STDOUT "sig figs output is 1.23456789112345 $cows_come_home\n";
# perl contract68.pl
# perl contract68.pl 2>text55.txt >text56.txt
__END__
#end script begin output
term is 0.5
current is -0.00057
term is 0.25
current is 7.3
term is 0.125
current is 7.3
term is 0.0625
current is 7.3
term is 0.03125
current is 7.3
term is 0.015625
current is 7.3
term is 0.0078125
current is 7.315625
term is 0.00390625
current is 7.315625
term is 0.001953125
current is 7.31953125
term is 0.0009765625
current is 7.321484375
term is 0.00048828125
current is 7.321484375
term is 0.000244140625
current is 7.321484375
term is 0.0001220703125
current is 7.321728515625
term is 6.103515625e-005
current is 7.3218505859375
term is 3.0517578125e-005
current is 7.32191162109375
term is 1.52587890625e-005
current is 7.32191162109375
term is 7.62939453125e-006
current is 7.32192687988281
term is 3.814697265625e-006
current is 7.32192687988281
term is 1.9073486328125e-006
current is 7.32192687988281
term is 9.5367431640625e-007
current is 7.32192687988281
term is 4.76837158203125e-007
current is 7.32192783355713
term is 2.38418579101563e-007
current is 7.32192783355713
term is 1.19209289550781e-007
current is 7.32192807197571
term is 5.96046447753906e-008
current is 7.32192807197571
term is 2.98023223876953e-008
current is 7.32192807197571
term is 1.49011611938477e-008
current is 7.32192807197571
term is 7.45058059692383e-009
current is 7.32192808687687
term is 3.72529029846191e-009
current is 7.32192809432745
term is 1.86264514923096e-009
current is 7.32192809432745
term is 9.31322574615479e-010
current is 7.32192809432745
term is 4.65661287307739e-010
current is 7.32192809432745
term is 2.3283064365387e-010
current is 7.32192809479311
term is 1.16415321826935e-010
current is 7.32192809479311
term is 5.82076609134674e-011
current is 7.32192809479311
term is 2.91038304567337e-011
current is 7.32192809485132
x_calc output is 7.32192809488042
x_sought output is 7.32192809488736
sig figs output is 1.23456789112345 0
#end output begin comment
I hope that aligns.
I'll try to beautify with those same changes as you made above. Thx.
--
wade ward
wade@xxxxxxxxxxx
435 -838-7760
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
.
- Follow-Ups:
- Re: equivalent controls
- From: Jürgen Exner
- Re: equivalent controls
- References:
- equivalent controls
- From: Wade Ward
- Re: equivalent controls
- From: Jürgen Exner
- equivalent controls
- Prev by Date: Re: making the keys of a hash from parameters collected from a form-2nd last line had an incorrect variable name. Sorry.
- Next by Date: Re: How to persist and query a hash lookup in memory with Perl ?
- Previous by thread: Re: equivalent controls
- Next by thread: Re: equivalent controls
- Index(es):
Relevant Pages
|