diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-06-20 01:16:55 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-20 01:16:55 +0100 |
| commit | 3c721fd7cdcea313d80381350fb247930b1f5a9d (patch) | |
| tree | 6e5b32e57aecffca71cf0f14a17c211982194559 /challenge-169 | |
| parent | 968a5b204b0247a6ca34359f271db9dd00c74d72 (diff) | |
| parent | 6a9feeb8fdbf9ee0abfed66d51bda92b443c1801 (diff) | |
| download | perlweeklychallenge-club-3c721fd7cdcea313d80381350fb247930b1f5a9d.tar.gz perlweeklychallenge-club-3c721fd7cdcea313d80381350fb247930b1f5a9d.tar.bz2 perlweeklychallenge-club-3c721fd7cdcea313d80381350fb247930b1f5a9d.zip | |
Merge pull request #6297 from drbaggy/master
Some notes - and numbers....
Diffstat (limited to 'challenge-169')
| -rw-r--r-- | challenge-169/james-smith/README.md | 192 | ||||
| -rw-r--r-- | challenge-169/james-smith/perl/ch-1-npp.pl | 6 | ||||
| -rw-r--r-- | challenge-169/james-smith/perl/ch-1.pl | 6 | ||||
| -rw-r--r-- | challenge-169/james-smith/perl/ch-2-npp.pl | 6 | ||||
| -rw-r--r-- | challenge-169/james-smith/perl/ch-2.pl | 8 |
5 files changed, 149 insertions, 69 deletions
diff --git a/challenge-169/james-smith/README.md b/challenge-169/james-smith/README.md index ba9c64a2b4..5c699ca4f3 100644 --- a/challenge-169/james-smith/README.md +++ b/challenge-169/james-smith/README.md @@ -30,7 +30,7 @@ For flexibility we define the max count `$MAX` as the command-line argument if o ```perl for( my( $MAX, $c, $n, @f ) = ($ARGV[0] // 1e2, 0); $c<$MAX; ) { - printf "%8d: %10d = %5d x %d\n", ++$c, $n, @f if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1]; + printf "%8d: %10d = %5d x %d\n", ++$c, $n, @f if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1] } ``` @@ -44,6 +44,8 @@ The output in each row is the brilliant number and the two primes which are it's **Moan:** Why is there no `sayf` function similar to `printf` - using `say sprintf` is just "messy" each time... +The first 50 brilliant numbers are: + ``` 1: 4 = 2 x 2 2: 6 = 2 x 3 @@ -96,14 +98,13 @@ The output in each row is the brilliant number and the two primes which are it's 49: 703 = 19 x 37 50: 713 = 23 x 31 ``` - ### Removing pretty print If we remove the pretty print this reduces to: ```perl for( my( $c, $n, @f ) = 100; $c; ) { - $c--, say $n if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1]; + $c--, say $n if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1] } ``` @@ -133,62 +134,141 @@ We then compute the `gcd` of these powers - if it is 1 then we display the resul ```perl for( my( $MAX, $c, $n, @f ) = ($ARGV[0] // 1e2, 0); $c<$MAX; ) { printf "%6d: %15d = %s\n", ++$c, $n, join ' . ', map { join '^', @$_ } @f - if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp ++$n; + if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp ++$n } ``` The following are the first 50 achilles numbers. -``` - 1: 72 = 2^3 . 3^2 - 2: 108 = 2^2 . 3^3 - 3: 200 = 2^3 . 5^2 - 4: 288 = 2^5 . 3^2 - 5: 392 = 2^3 . 7^2 - 6: 432 = 2^4 . 3^3 - 7: 500 = 2^2 . 5^3 - 8: 648 = 2^3 . 3^4 - 9: 675 = 3^3 . 5^2 - 10: 800 = 2^5 . 5^2 - 11: 864 = 2^5 . 3^3 - 12: 968 = 2^3 . 11^2 - 13: 972 = 2^2 . 3^5 - 14: 1125 = 3^2 . 5^3 - 15: 1152 = 2^7 . 3^2 - 16: 1323 = 3^3 . 7^2 - 17: 1352 = 2^3 . 13^2 - 18: 1372 = 2^2 . 7^3 - 19: 1568 = 2^5 . 7^2 - 20: 1800 = 2^3 . 3^2 . 5^2 - 21: 1944 = 2^3 . 3^5 - 22: 2000 = 2^4 . 5^3 - 23: 2312 = 2^3 . 17^2 - 24: 2592 = 2^5 . 3^4 - 25: 2700 = 2^2 . 3^3 . 5^2 - 26: 2888 = 2^3 . 19^2 - 27: 3087 = 3^2 . 7^3 - 28: 3200 = 2^7 . 5^2 - 29: 3267 = 3^3 . 11^2 - 30: 3456 = 2^7 . 3^3 - 31: 3528 = 2^3 . 3^2 . 7^2 - 32: 3872 = 2^5 . 11^2 - 33: 3888 = 2^4 . 3^5 - 34: 4000 = 2^5 . 5^3 - 35: 4232 = 2^3 . 23^2 - 36: 4500 = 2^2 . 3^2 . 5^3 - 37: 4563 = 3^3 . 13^2 - 38: 4608 = 2^9 . 3^2 - 39: 5000 = 2^3 . 5^4 - 40: 5292 = 2^2 . 3^3 . 7^2 - 41: 5324 = 2^2 . 11^3 - 42: 5400 = 2^3 . 3^3 . 5^2 - 43: 5408 = 2^5 . 13^2 - 44: 5488 = 2^4 . 7^3 - 45: 6075 = 3^5 . 5^2 - 46: 6125 = 5^3 . 7^2 - 47: 6272 = 2^7 . 7^2 - 48: 6728 = 2^3 . 29^2 - 49: 6912 = 2^8 . 3^3 - 50: 7200 = 2^5 . 3^2 . 5^2 + +| Index | Value | Factors | +| -----------: | -------------------: | ------------------------------------------------------------ | +| 1 | 72 | 2<sup>3</sup>.3<sup>2</sup> | +| 2 | 108 | 2<sup>2</sup>.3<sup>3</sup> | +| 3 | 200 | 2<sup>3</sup>.5<sup>2</sup> | +| 4 | 288 | 2<sup>5</sup>.3<sup>2</sup> | +| 5 | 392 | 2<sup>3</sup>.7<sup>2</sup> | +| 6 | 432 | 2<sup>4</sup>.3<sup>3</sup> | +| 7 | 500 | 2<sup>2</sup>.5<sup>3</sup> | +| 8 | 648 | 2<sup>3</sup>.3<sup>4</sup> | +| 9 | 675 | 3<sup>3</sup>.5<sup>2</sup> | +| 10 | 800 | 2<sup>5</sup>.5<sup>2</sup> | +| 11 | 864 | 2<sup>5</sup>.3<sup>3</sup> | +| 12 | 968 | 2<sup>3</sup>.11<sup>2</sup> | +| 13 | 972 | 2<sup>2</sup>.3<sup>5</sup> | +| 14 | 1,125 | 3<sup>2</sup>.5<sup>3</sup> | +| 15 | 1,152 | 2<sup>7</sup>.3<sup>2</sup> | +| 16 | 1,323 | 3<sup>3</sup>.7<sup>2</sup> | +| 17 | 1,352 | 2<sup>3</sup>.13<sup>2</sup> | +| 18 | 1,372 | 2<sup>2</sup>.7<sup>3</sup> | +| 19 | 1,568 | 2<sup>5</sup>.7<sup>2</sup> | +| 20 | 1,800 | 2<sup>3</sup>.3<sup>2</sup>.5<sup>2</sup> | +| 21 | 1,944 | 2<sup>3</sup>.3<sup>5</sup> | +| 22 | 2,000 | 2<sup>4</sup>.5<sup>3</sup> | +| 23 | 2,312 | 2<sup>3</sup>.17<sup>2</sup> | +| 24 | 2,592 | 2<sup>5</sup>.3<sup>4</sup> | +| 25 | 2,700 | 2<sup>2</sup>.3<sup>3</sup>.5<sup>2</sup> | +| 26 | 2,888 | 2<sup>3</sup>.19<sup>2</sup> | +| 27 | 3,087 | 3<sup>2</sup>.7<sup>3</sup> | +| 28 | 3,200 | 2<sup>7</sup>.5<sup>2</sup> | +| 29 | 3,267 | 3<sup>3</sup>.11<sup>2</sup> | +| 30 | 3,456 | 2<sup>7</sup>.3<sup>3</sup> | +| 31 | 3,528 | 2<sup>3</sup>.3<sup>2</sup>.7<sup>2</sup> | +| 32 | 3,872 | 2<sup>5</sup>.11<sup>2</sup> | +| 33 | 3,888 | 2<sup>4</sup>.3<sup>5</sup> | +| 34 | 4,000 | 2<sup>5</sup>.5<sup>3</sup> | +| 35 | 4,232 | 2<sup>3</sup>.23<sup>2</sup> | +| 36 | 4,500 | 2<sup>2</sup>.3<sup>2</sup>.5<sup>3</sup> | +| 37 | 4,563 | 3<sup>3</sup>.13<sup>2</sup> | +| 38 | 4,608 | 2<sup>9</sup>.3<sup>2</sup> | +| 39 | 5,000 | 2<sup>3</sup>.5<sup>4</sup> | +| 40 | 5,292 | 2<sup>2</sup>.3<sup>3</sup>.7<sup>2</sup> | +| 41 | 5,324 | 2<sup>2</sup>.11<sup>3</sup> | +| 42 | 5,400 | 2<sup>3</sup>.3<sup>3</sup>.5<sup>2</sup> | +| 43 | 5,408 | 2<sup>5</sup>.13<sup>2</sup> | +| 44 | 5,488 | 2<sup>4</sup>.7<sup>3</sup> | +| 45 | 6,075 | 3<sup>5</sup>.5<sup>2</sup> | +| 46 | 6,125 | 5<sup>3</sup>.7<sup>2</sup> | +| 47 | 6,272 | 2<sup>7</sup>.7<sup>2</sup> | +| 48 | 6,728 | 2<sup>3</sup>.29<sup>2</sup> | +| 49 | 6,912 | 2<sup>8</sup>.3<sup>3</sup> | +| 50 | 7,200 | 2<sup>5</sup>.3<sup>2</sup>.5<sup>2</sup> | + + +Some examples for larger values of `n` are: + +| Index | Value | Factors | +| -----------: | -------------------: | ------------------------------------------------------------ | +| 100 | 21,600 | 2<sup>5</sup>.3<sup>3</sup>.5<sup>2</sup> | +| 200 | 66,248 | 2<sup>3</sup>.7<sup>2</sup>.13<sup>2</sup> | +| 300 | 136,107 | 3<sup>3</sup>.71<sup>2</sup> | +| 400 | 225,000 | 2<sup>3</sup>.3<sup>2</sup>.5<sup>5</sup> | +| 500 | 333,396 | 2<sup>2</sup>.3<sup>5</sup>.7<sup>3</sup> | +| 600 | 464,648 | 2<sup>3</sup>.241<sup>2</sup> | +| 700 | 617,400 | 2<sup>3</sup>.3<sup>2</sup>.5<sup>2</sup>.7<sup>3</sup> | +| 800 | 784,000 | 2<sup>7</sup>.5<sup>3</sup>.7<sup>2</sup> | +| 900 | 969,624 | 2<sup>3</sup>.3<sup>3</sup>.67<sup>2</sup> | +| 1,000 | 1,179,648 | 2<sup>17</sup>.3<sup>2</sup> | +| 2,000 | 4,255,443 | 3<sup>3</sup>.397<sup>2</sup> | +| 3,000 | 9,082,800 | 2<sup>4</sup>.3<sup>3</sup>.5<sup>2</sup>.29<sup>2</sup> | +| 4,000 | 15,635,232 | 2<sup>5</sup>.3<sup>2</sup>.233<sup>2</sup> | +| 5,000 | 23,876,179 | 19<sup>3</sup>.59<sup>2</sup> | +| 6,000 | 33,818,428 | 2<sup>2</sup>.7<sup>3</sup>.157<sup>2</sup> | +| 7,000 | 45,489,708 | 2<sup>2</sup>.3<sup>3</sup>.11<sup>2</sup>.59<sup>2</sup> | +| 8,000 | 58,752,800 | 2<sup>5</sup>.5<sup>2</sup>.271<sup>2</sup> | +| 9,000 | 73,641,248 | 2<sup>5</sup>.37<sup>2</sup>.41<sup>2</sup> | +| 10,000 | 90,209,312 | 2<sup>5</sup>.23<sup>2</sup>.73<sup>2</sup> | +| 20,000 | 344,478,752 | 2<sup>5</sup>.17<sup>2</sup>.193<sup>2</sup> | +| 30,000 | 758,595,456 | 2<sup>7</sup>.3<sup>5</sup>.29<sup>3</sup> | +| 40,000 | 1,330,259,301 | 3<sup>3</sup>.7<sup>3</sup>.379<sup>2</sup> | +| 50,000 | 2,057,748,300 | 2<sup>2</sup>.3<sup>7</sup>.5<sup>2</sup>.97<sup>2</sup> | +| 60,000 | 2,941,077,600 | 2<sup>5</sup>.3<sup>7</sup>.5<sup>2</sup>.41<sup>2</sup> | +| 70,000 | 3,978,593,667 | 3<sup>3</sup>.61<sup>2</sup>.199<sup>2</sup> | +| 80,000 | 5,171,352,984 | 2<sup>3</sup>.3<sup>5</sup>.7<sup>2</sup>.233<sup>2</sup> | +| 90,000 | 6,518,604,456 | 2<sup>3</sup>.3<sup>2</sup>.7<sup>2</sup>.13<sup>3</sup>.29<sup>2</sup> | +| 100,000 | 8,017,975,944 | 2<sup>3</sup>.3<sup>3</sup>.11<sup>3</sup>.167<sup>2</sup> | +| 125,000 | 12,437,566,904 | 2<sup>3</sup>.7<sup>3</sup>.2129<sup>2</sup> | +| 150,000 | 17,810,638,848 | 2<sup>11</sup>.3<sup>2</sup>.983<sup>2</sup> | +| 175,000 | 24,140,196,992 | 2<sup>7</sup>.31<sup>2</sup>.443<sup>2</sup> | +| 200,000 | 31,413,171,744 | 2<sup>5</sup>.3<sup>2</sup>.17<sup>3</sup>.149<sup>2</sup> | +| 225,000 | 39,636,156,125 | 5<sup>3</sup>.17807<sup>2</sup> | +| 250,000 | 48,804,377,888 | 2<sup>5</sup>.7<sup>4</sup>.797<sup>2</sup> | +| 275,000 | 58,919,206,088 | 2<sup>3</sup>.85819<sup>2</sup> | +| 300,000 | 69,976,609,587 | 3<sup>3</sup>.50909<sup>2</sup> | +| 325,000 | 81,981,196,443 | 3<sup>3</sup>.55103<sup>2</sup> | +| 350,000 | 94,917,245,000 | 2<sup>3</sup>.5<sup>4</sup>.4357<sup>2</sup> | + +And these are the first numbers with `n` digits... + +| Index | Value | Factors | +| -----------: | -------------------: | ------------------------------------------------------------ | +| 1 | 72 | 2<sup>3</sup>.3<sup>2</sup> | +| 2 | 108 | 2<sup>2</sup>.3<sup>3</sup> | +| 14 | 1,125 | 3<sup>2</sup>.5<sup>3</sup> | +| 61 | 10,125 | 3<sup>4</sup>.5<sup>3</sup> | +| 253 | 100,352 | 2<sup>11</sup>.7<sup>2</sup> | +| 917 | 1,000,188 | 2<sup>2</sup>.3<sup>6</sup>.7<sup>3</sup> | +| 3,159 | 10,011,125 | 5<sup>3</sup>.283<sup>2</sup> | +| 10,554 | 100,018,800 | 2<sup>4</sup>.3<sup>6</sup>.5<sup>2</sup>.7<sup>3</sup> | +| 34,562 | 1,000,042,200 | 2<sup>3</sup>.3<sup>6</sup>.5<sup>2</sup>.19<sup>3</sup> | +| 111,892 | 10,000,373,888 | 2<sup>7</sup>.8839<sup>2</sup> | +| 359,341 | 100,001,075,328 | 2<sup>7</sup>.3<sup>2</sup>.7<sup>2</sup>.11<sup>6</sup> | + +### Github formatting script.... + +To convert from the human readable text file generated by the script to github markup I wrote this script: + +```perl +head(); +while( <> ) { + head(), next unless /\S/; + my ($c,$n,$p) = m{(\d+):\s+(\d+)\s+=\s+(.*)$}; + printf "| %12s | %20s | %-60s |\n", th($c), th($n), + join q(.), map { sprintf '%d<sup>%d</sup>', split /\^/ } split / \. /, $p +} + +sub head { print "\n| Index | Value | Factors | +| -----------: | -------------------: | ------------------------------------------------------------ |\n" } +sub th { scalar reverse ( (reverse $_[0]) =~ s/(\d\d\d)(?=\d)(?!\d*\.)/$1,/gr ) } ``` ### Removing pretty print @@ -196,7 +276,7 @@ If we remove the pretty print this reduces to: ```perl for( my( $c, $n ) = 100; $c; ) { - $c--, say $n if 1 == gcd map{ $_->[1] < 2 ? next : $_->[1] } factor_exp ++$n; + $c--, say $n if 1 == gcd map{ $_->[1] < 2 ? next : $_->[1] } factor_exp ++$n } ``` diff --git a/challenge-169/james-smith/perl/ch-1-npp.pl b/challenge-169/james-smith/perl/ch-1-npp.pl index ce0b88c777..6b5c2d4c3b 100644 --- a/challenge-169/james-smith/perl/ch-1-npp.pl +++ b/challenge-169/james-smith/perl/ch-1-npp.pl @@ -10,9 +10,9 @@ use Time::HiRes qw(time); my $time = time; #------------------------------------------------------------------------------- -for( my( $c, $n, @f ) = 100; $c; ) { - $c--, say $n if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1]; +for( my( $c, $n, @f ) = $ARGV[0] // 100; $c; ) { + $c--, say $n if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1] } -warn 'Time taken: ', time-$time, "\n"; +warn 'Time taken: ', time-$time, "\n" diff --git a/challenge-169/james-smith/perl/ch-1.pl b/challenge-169/james-smith/perl/ch-1.pl index 775040f182..5671e8ce07 100644 --- a/challenge-169/james-smith/perl/ch-1.pl +++ b/challenge-169/james-smith/perl/ch-1.pl @@ -13,10 +13,10 @@ my $time = time; # must have preciesely 2 prime factors # THEN each factor must be the same length; -for( my( $MAX, $c, $n, @f ) = ($ARGV[0] // 1e2,0); $c < $MAX; ) { +for( my( $MAX, $c, $n, @f ) = ( $ARGV[0] // 100, 0 ); $c < $MAX; ) { printf "%8d: %10d = %5d x %d\n", ++$c, $n, @f - if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1]; + if 2 == ( @f = factor ++$n ) && length $f[0] == length $f[1] } -warn 'Time taken: ', time-$time, "\n"; +warn 'Time taken: ', time-$time, "\n" diff --git a/challenge-169/james-smith/perl/ch-2-npp.pl b/challenge-169/james-smith/perl/ch-2-npp.pl index a3d686dc25..590e015325 100644 --- a/challenge-169/james-smith/perl/ch-2-npp.pl +++ b/challenge-169/james-smith/perl/ch-2-npp.pl @@ -10,9 +10,9 @@ use Time::HiRes qw(time); my $time = time; #------------------------------------------------------------------------------- -for( my( $c, $n ) = ( 100 ); $c; ) { - $c--, say $n if 1 == gcd map{ $_->[1] < 2 ? next : $_->[1] } factor_exp ++$n; +for( my( $c, $n ) = $ARGV[0] // 100; $c; ) { + $c--, say $n if 1 == gcd map{ $_->[1] < 2 ? next : $_->[1] } factor_exp ++$n } -warn 'Time taken: ', time-$time, "\n"; +warn 'Time taken: ', time-$time, "\n" diff --git a/challenge-169/james-smith/perl/ch-2.pl b/challenge-169/james-smith/perl/ch-2.pl index c55acdc58d..f6477524ae 100644 --- a/challenge-169/james-smith/perl/ch-2.pl +++ b/challenge-169/james-smith/perl/ch-2.pl @@ -1,4 +1,4 @@ -#!/usr/local/bin/perl +#/usr/local/bin/perl use strict; @@ -26,10 +26,10 @@ my $time = time; # To pretty print the archilles numbers - we use our counter, and display # it alongside the number and the factorisation. -for( my( $MAX, $c, $n, @f ) = ($ARGV[0] // 1e2,0); $c<$MAX; ) { +for( my( $MAX, $c, $n, @f ) = ( $ARGV[0] // 100, 0 ); $c < $MAX; ) { say sprintf '%6d: %15d = %s', ++$c, $n, join ' . ', map { join '^', @$_ } @f - if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp ++$n; + if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp ++$n } -warn 'Time taken: ', time-$time, "\n"; +warn 'Time taken: ', time-$time, "\n" |
