perlmoth has asked for the wisdom of the Perl Monks concerning the following question:
1. Is there a better way to write it, that would enable it to be scaled up to multiplcations of any size?#!/usr/bin/perl -w use strict; my @fr = ([], [], [], [], []); my $low_count; for my $x (10 .. 99) { for my $y (101 .. 999) { my $result = $x * $y; if ($result < 10000) { $low_count++; next; } $result =~ m/(\d)?(\d)?(\d)?(\d)?(\d)?/; $fr[0][$5]++; $fr[1][$4]++; $fr[2][$3]++; $fr[3][$2]++; $fr[4][$1]++; } } $fr[4][0] = 0; #This line print "$low_count\n\n"; for my $digit (0 .. 9) { print "$digit\t"; for my $exp (reverse 0 .. 4) { print "$fr[$exp][$digit]\t"; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Frequency analysis of the digits of the result of a multiplication
by Masem (Monsignor) on Nov 17, 2001 at 23:54 UTC | |
by perlmoth (Hermit) on Nov 18, 2001 at 22:46 UTC | |
|
Re: Frequency analysis of the digits of the result of a multiplication
by demerphq (Chancellor) on Nov 18, 2001 at 01:07 UTC | |
|
Re: Frequency analysis of the digits of the result of a multiplication
by grinder (Bishop) on Nov 17, 2001 at 23:56 UTC | |
|
Re: Frequency analysis of the digits of the result of a multiplication
by hopes (Friar) on Nov 18, 2001 at 01:19 UTC | |
|
Re: Frequency analysis of the digits of the result of a multiplication
by pjf (Curate) on Nov 18, 2001 at 01:57 UTC |