in reply to Nested loops and if
Use a numeric relational operator rather than a stringwise one
#scalar @cleared lt scalar @bestincurrentprime
scalar @cleared < scalar @bestincurrentprime
and less importantly here
#grep { ($_+$y) % $x ne 0}Update : cut down version
poj#!/usr/bin/env perl use warnings; use strict; my @primes = (2,3,5,7,11,13,17) ; my @start = (0..209); foreach my $x (@primes){ my @best = @start; my $count = scalar @best; print "\nprime $x $count\n"; foreach my $y (0..$x-1){ my @new = grep { ($_+$y) % $x } @best; my $new = scalar @new; print " ${y}mod${x} = $new\n"; if ($new < @start){ @start = @new; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Nested loops and if
by robert44444uk (Acolyte) on Feb 21, 2016 at 18:40 UTC | |
by poj (Abbot) on Feb 21, 2016 at 19:03 UTC | |
by robert44444uk (Acolyte) on Feb 21, 2016 at 22:15 UTC | |
|
Re^2: Nested loops and if
by robert44444uk (Acolyte) on Feb 21, 2016 at 08:16 UTC |