I'm sorry to trouble again, but I am wondering how I record the $y with the lowest $new for each $x and place this in a file ready for a CRT calculation, given by the "push" command in the program below. For the CRT calculation I only need one $y for each $x, otherwise the CRT calculation will not work. For example, running this code produces 0,11 as well as 5,11 in @results and it is only the last value at for each prime that I need to keep (i.e. 5,11

#!/usr/bin/env perl use warnings; foreach my $x (@primes){ my @best = @start; my $count = scalar @best; use strict; my @primes = (2,3,5,7,11,13,17) ; my @start = (0..209); my @results =(); 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; push ( @results, ("[","$y",",","$x","],")); } } } foreach (@start) { print "$_\n"; } print "@results\n";

In reply to Re^2: Nested loops and if by robert44444uk
in thread Nested loops and if by robert44444uk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.