in reply to help with simplifying program
From your description I take you want (w, x, y, z) such that 0 <= z < y < x < w <= 100 and not w-x == x-y == y-z. In order to achieve this I would parametrize the loops using the differences dwx = w-x, dxy = x-y, dyz = y-z.
UPDATE: Changes next unless... for better readibility.use strict; use warnings; my $n = 5; # should be 100 my $c1 = my $c2 = 0; for my $w (3..$n) { for my $dwx (1..$w-2) { my $x = $w - $dwx; for my $dxy (1..$x-1) { my $y = $x - $dxy; for my $dyz (1..$y) { my $z = $y - $dyz; $c1++; next unless $dwx != $dxy or $dxy != $dyz; $c2++; print "$w $x $y $z\n"; } } } } print "Found $c2 out of $c1 combinations\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: help with simplifying program
by Anonymous Monk on May 24, 2013 at 12:41 UTC | |
by hdb (Monsignor) on May 24, 2013 at 12:46 UTC | |
by Anonymous Monk on May 24, 2013 at 12:54 UTC |