aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-150/bruce-gray/README73
-rw-r--r--challenge-150/bruce-gray/blog.txt1
-rw-r--r--challenge-150/bruce-gray/dart/ch-1.dart14
-rw-r--r--challenge-150/bruce-gray/dart/ch-2.dart23
-rw-r--r--challenge-150/bruce-gray/perl/ch-1.pl12
-rw-r--r--challenge-150/bruce-gray/perl/ch-2.pl4
-rw-r--r--challenge-150/bruce-gray/raku/ch-1.raku11
-rw-r--r--challenge-150/bruce-gray/raku/ch-2.raku5
8 files changed, 71 insertions, 72 deletions
diff --git a/challenge-150/bruce-gray/README b/challenge-150/bruce-gray/README
index cec9d84ed8..58a8668633 100644
--- a/challenge-150/bruce-gray/README
+++ b/challenge-150/bruce-gray/README
@@ -1,72 +1 @@
-Solutions by Bruce Gray for https://theweeklychallenge.org/blog/perl-weekly-challenge-149/
-Languages: Raku, Perl, C
-
-Task 1: Generate https://oeis.org/A028840
-Task 2: Generate https://oeis.org/A287298
-
-Sample runs:
-$ perl perl/ch-1.pl 30
-$ raku raku/ch-1.raku 30
-$ gcc -Wall c/ch-1.c && ./a.out 30
- All have the output:
- 0, 1, 2, 3, 5, 8, 10, 11, 12, 14, 17, 20, 21, 23, 26, 30, 32, 35, 41, 44, 49, 50, 53, 58, 62, 67, 71, 76, 80, 85
-
-$ perl perl/ch-2.pl 2-12 14-16 18-19
- 2 1 1 1 1
- 3 1 1 1 1
- 4 15 225 33 3201
- 5 24 576 44 4301
- 6 195 38025 523 452013
- 7 867 751689 2346 6250341
- 8 3213 10323369 6215 47302651
- 9 18858 355624164 27773 823146570
- 10 99066 9814072356 99066 9814072356
- 11 528905 279740499025 331413 A8701245369
- 12 2950717 8706730814089 BA3711 B8750A649321
- 14 105011842 11027486960232964 DD3789C DC71B30685A924
- 15 659854601 435408094460869201 3CDE271B EDAC93B24658701
- 16 4285181505 18362780530794065025 FF6AAE41 FED5B39A42706C81
- 18 198009443151 3.92077395769691e+22 HH7CF68B9 HGF80ADC537126GBH2
- 19 1404390324525 1.97231218361943e+24 46D29B1F53 IHGFD3408C68ID1IBG7
-(21m38s runtime)
-$ raku raku/ch-2.raku 2-12 14-16 18-19
- 2 1 1 1 1
- 3 1 1 1 1
- 4 15 225 33 3201
- 5 24 576 44 4301
- 6 195 38025 523 452013
- 7 867 751689 2346 6250341
- 8 3213 10323369 6215 47302651
- 9 18858 355624164 27773 823146570
- 10 99066 9814072356 99066 9814072356
- 11 528905 279740499025 331413 A8701245369
- 12 2950717 8706730814089 BA3711 B8750A649321
- 14 105011842 11027486960232964 DD3789C DC71B30685A924
- 15 659854601 435408094460869201 3CDE271B EDAC93B24658701
- 16 4285181505 18362780530794065025 FF6AAE41 FED5B39A42706C81
- 18 198009443151 39207739576969100808801 HH7CF68B9 HGF80ADC53712EB649
- 19 1404390324525 1972312183619434816475625 46D29B1F53 IHGFD3408C6E715A2B9
-(4m51s runtime)
-$ gcc -Wall -lgmp c/ch-2.c && ./a.out 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 22 23 24
-f(2)='1'
-f(3)='1'
-f(4)='3201'
-f(5)='4301'
-f(6)='452013'
-f(7)='6250341'
-f(8)='47302651'
-f(9)='823146570'
-f(10)='9814072356'
-f(11)='a8701245369'
-f(12)='b8750a649321'
-f(13)='cba504216873'
-f(14)='dc71b30685a924'
-f(15)='edac93b24658701'
-f(16)='fed5b39a42706c81'
-f(18)='hgf80adc53712eb649'
-f(19)='ihgfd3408c6e715a2b9'
-f(20)='jihg03dac457bfe96281'
-f(22)='lkjig5d14b9032fhac867e'
-f(23)='mlkjefg5ic1d9h8042ab376'
-f(24)='nmlkjbgc6a0d579482i3efh1'
-(13m20s runtime)
+Solutions by Bruce Gray
diff --git a/challenge-150/bruce-gray/blog.txt b/challenge-150/bruce-gray/blog.txt
new file mode 100644
index 0000000000..6f90f4ad74
--- /dev/null
+++ b/challenge-150/bruce-gray/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/bruce_gray/2022/02/twc-150-bababbab-and-a-few-composites.html
diff --git a/challenge-150/bruce-gray/dart/ch-1.dart b/challenge-150/bruce-gray/dart/ch-1.dart
new file mode 100644
index 0000000000..bac1736ad1
--- /dev/null
+++ b/challenge-150/bruce-gray/dart/ch-1.dart
@@ -0,0 +1,14 @@
+String task1(a, b, n) {
+ while (b.length < n) {
+ var t = a + b;
+ a = b;
+ b = t;
+ }
+ return b.substring(n - 1, n);
+}
+
+void main(List<String> args) {
+ var a = args.isNotEmpty ? args : ["1234", "5678"];
+
+ print(task1(a[0], a[1], 51));
+}
diff --git a/challenge-150/bruce-gray/dart/ch-2.dart b/challenge-150/bruce-gray/dart/ch-2.dart
new file mode 100644
index 0000000000..d3bbff0b7a
--- /dev/null
+++ b/challenge-150/bruce-gray/dart/ch-2.dart
@@ -0,0 +1,23 @@
+import 'dart:math';
+
+bool isSquareFree(int n) {
+ int root = sqrt(n).toInt();
+ for (int i = 2; i <= root; i++) {
+ if (n % i == 0) {
+ n ~/= i;
+ if (n % i == 0) {
+ return false;
+ }
+ root = sqrt(n).toInt();
+ }
+ }
+ return true;
+}
+
+void main() {
+ var sFree = [
+ for (int i = 1; i <= 500; i++)
+ if (isSquareFree(i)) i
+ ];
+ print(sFree.join(', '));
+}
diff --git a/challenge-150/bruce-gray/perl/ch-1.pl b/challenge-150/bruce-gray/perl/ch-1.pl
new file mode 100644
index 0000000000..ed66449012
--- /dev/null
+++ b/challenge-150/bruce-gray/perl/ch-1.pl
@@ -0,0 +1,12 @@
+use Modern::Perl;
+use experimental qw<signatures>;
+
+sub task1 ( $x, $y, $pos ) {
+ return substr $x, $pos-1, 1 if length($x) < $pos;
+ ($x, $y) = ($y, "$x$y") while length($y) < $pos;
+ return substr $y, $pos-1, 1;
+}
+
+@ARGV = qw<1234 5678> if not @ARGV;
+die if @ARGV != 2;
+say task1( @ARGV, 51 );
diff --git a/challenge-150/bruce-gray/perl/ch-2.pl b/challenge-150/bruce-gray/perl/ch-2.pl
new file mode 100644
index 0000000000..e769348e37
--- /dev/null
+++ b/challenge-150/bruce-gray/perl/ch-2.pl
@@ -0,0 +1,4 @@
+use Modern::Perl;
+use ntheory qw<is_square_free>;
+
+say join ', ', grep { is_square_free($_) } 1 .. 500;
diff --git a/challenge-150/bruce-gray/raku/ch-1.raku b/challenge-150/bruce-gray/raku/ch-1.raku
new file mode 100644
index 0000000000..f280ca9863
--- /dev/null
+++ b/challenge-150/bruce-gray/raku/ch-1.raku
@@ -0,0 +1,11 @@
+sub task1 ( Str $s1, Str $s2, UInt $n ) {
+ return ( $s1, $s2, * ~ * … {.chars >= $n} ).tail.substr($n-1, 1);
+}
+multi sub MAIN ( $a, $b ) {
+ say task1( $a, $b, 51 );
+}
+multi sub MAIN ( ) {
+ use Test;
+ plan 1;
+ is task1( |<1234 5678>, 51 ), '7', '51st char of Fib_substr(1234 5678) is "7"';
+}
diff --git a/challenge-150/bruce-gray/raku/ch-2.raku b/challenge-150/bruce-gray/raku/ch-2.raku
new file mode 100644
index 0000000000..01b0ff4b0e
--- /dev/null
+++ b/challenge-150/bruce-gray/raku/ch-2.raku
@@ -0,0 +1,5 @@
+use Prime::Factor;
+
+sub is-square-free ( UInt $n ) { $n.&prime-factors.repeated.not }
+
+say join ', ', grep &is-square-free, 1..500;