diff options
Diffstat (limited to 'challenge-246')
| -rw-r--r-- | challenge-246/laurent-rosenfeld/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-246/laurent-rosenfeld/perl/ch-2.pl | 26 | ||||
| -rw-r--r-- | challenge-246/laurent-rosenfeld/raku/ch-2.raku | 21 | ||||
| -rw-r--r-- | challenge-246/robert-dicicco/raku/ch-1.raku | 29 |
4 files changed, 77 insertions, 0 deletions
diff --git a/challenge-246/laurent-rosenfeld/blog1.txt b/challenge-246/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..0e28fd88c0 --- /dev/null +++ b/challenge-246/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2023/12/perl-weekly-challenge-246-linear-recurrence-of-second-order.html diff --git a/challenge-246/laurent-rosenfeld/perl/ch-2.pl b/challenge-246/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..fa464dfdcf --- /dev/null +++ b/challenge-246/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,26 @@ +use strict; +use warnings; +use feature 'say'; + +sub linear_rec { + my @in = @_; + my ($min, $max) = (sort {$a <=> $b} @in)[0, -1]; + for my $p ($min .. $max) { + for my $q ($min .. $max) { + for my $i (2..$#in) { + last if $in[$i] != + $p * $in[$i-2] + $q * $in[$i-1]; + # say "$p $q $i"; + return ("True: p = $p, q = $q") + if $i == $#in; + } + } + } + return "False"; +} + +my @tests = ([<1 1 2 3 5>], [<4 2 4 5 7>], [<4 1 2 -3 8>]); +for my $test (@tests) { + printf "%-12s => ", "@$test"; + say linear_rec @$test; +} diff --git a/challenge-246/laurent-rosenfeld/raku/ch-2.raku b/challenge-246/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..9938c4a782 --- /dev/null +++ b/challenge-246/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,21 @@ +sub linear-rec (@in) { + my @range = @in.minmax; + for @range -> $p { + for @range -> $q { + for 2..@in.end -> $i { + last if @in[$i] != + $p * @in[$i-2] + $q * @in[$i-1]; + # say "$p $q $i"; + return ("True: p = $p, q = $q") + if $i == @in.end; + } + } + } + return (False); +} + +my @tests = <1 1 2 3 5>, <4 2 4 5 7>, <4 1 2 -3 8>; +for @tests -> @test { + printf "%-12s => ", "@test[]"; + say linear-rec @test; +} diff --git a/challenge-246/robert-dicicco/raku/ch-1.raku b/challenge-246/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..e4ad5a0a78 --- /dev/null +++ b/challenge-246/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku +=begin comment +------------------------------------- +AUTHOR: Robert DiCicco +DATE : 2023-12-06 +Challenge 246 6 Out of 49 ( Raku ) +------------------------------------- +=end comment + +use v6; + +my $cnt = 0; +my @out = (); +while 1 == 1 { + my $num = 49.rand.Int; + if $num > 0 { + @out.push: $num; + $cnt++; + } + last if $cnt == 6; +} +say @out.sort; + +=begin comment +------------------------------------- +SAMPLE OUTPUT +(3 15 25 27 29 42) +------------------------------------- +=end comment |
