diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-02 17:16:00 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-02-02 17:16:00 +0000 |
| commit | ea530bc5cf89e42ab0175eec72b2ebccfa3fdad4 (patch) | |
| tree | b0c67aab5f3f0b89abe7ec3eb107a7648a2f32e4 /challenge-150 | |
| parent | 05594b511709e75cc13c72043d2cec77bfeb5d3a (diff) | |
| download | perlweeklychallenge-club-ea530bc5cf89e42ab0175eec72b2ebccfa3fdad4.tar.gz perlweeklychallenge-club-ea530bc5cf89e42ab0175eec72b2ebccfa3fdad4.tar.bz2 perlweeklychallenge-club-ea530bc5cf89e42ab0175eec72b2ebccfa3fdad4.zip | |
- Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-150')
| -rw-r--r-- | challenge-150/robert-dicicco/perl/ch-1.pl | 38 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/perl/ch-2.pl | 35 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/raku/ch-1.raku | 26 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/raku/ch-2.raku | 30 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/ruby/ch-1.rb | 32 | ||||
| -rw-r--r-- | challenge-150/robert-dicicco/ruby/ch-2.rb | 47 |
6 files changed, 208 insertions, 0 deletions
diff --git a/challenge-150/robert-dicicco/perl/ch-1.pl b/challenge-150/robert-dicicco/perl/ch-1.pl new file mode 100644 index 0000000000..6441628bde --- /dev/null +++ b/challenge-150/robert-dicicco/perl/ch-1.pl @@ -0,0 +1,38 @@ +#!perl.exe + +use strict; +use warnings; +use 5.30.0; + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Fibonacci Words (Perl) + +my $a = '1234'; +my $b = '5678'; + +say "Fibonacci Words"; +say $a; +say $b; + +my $retval=Fib($a, $b); + +# get the 51st character +my $fibchr = substr($retval, 50, 1); +say "51st digit is $fibchr"; + +# recursive routine to create fibonacci series, but using strings + +sub Fib { + my $val = $_[0] . $_[1]; + say $val; + + # if new string length is less than 51, go another round using new combined string + + if (length($val) < 51) { + Fib($_[1], $val); + } else { + # return the string if length 51 or greater + return $val; + } +} diff --git a/challenge-150/robert-dicicco/perl/ch-2.pl b/challenge-150/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..ce7fca6c4b --- /dev/null +++ b/challenge-150/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,35 @@ +#!perl.exe + +use strict; +use warnings; +use ntheory qw/ factor /; +use 5.30.0; + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Square-Free Integer (Perl) + +my @sqfnums = (); + +foreach my $num (1..500){ + my @facs = factor($num); + my $retval = SquareFree (@facs); + if($retval > 0){ + push(@sqfnums, $num); + } +} + +say "@sqfnums "; + +sub SquareFree { + my %dvals = (); + foreach my $val (@_){ + if (! exists($dvals{$val})){ + $dvals{$val} = 1; + } else { + return -1; + } + } + + return 1; +} diff --git a/challenge-150/robert-dicicco/raku/ch-1.raku b/challenge-150/robert-dicicco/raku/ch-1.raku new file mode 100644 index 0000000000..b2694c044c --- /dev/null +++ b/challenge-150/robert-dicicco/raku/ch-1.raku @@ -0,0 +1,26 @@ +#!raku.exe + +# Author: Robert DiCicco +# Date: 01-FEB--2022 +# Challenge 150 Fibonacci Words (Raku) + +my $a = '1234'; +my $b = '5678'; + +say "Fibonacci Words"; +say $a; +say $b; + +my $retval = Fib( $a, $b ); +my $fibchr = substr($retval, 50, 1); +say "51st digit is $fibchr"; + +sub Fib ( $first, $second) { + my $val = $first ~ $second; + say $val; + if $val.chars < 51 { + Fib($second, $val); + } else { + return $val; + } +} diff --git a/challenge-150/robert-dicicco/raku/ch-2.raku b/challenge-150/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..ea362a9191 --- /dev/null +++ b/challenge-150/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,30 @@ +#!raku.exe + +use v6; +use Prime::Factor; + +# Author: Robert DiCicco +# Date: 01-FEB-2022 +# Challenge 150 Square-Free Integer (Raku) + +sub SquareFree { + my %dvals = (); + for @_ -> $num { + if %dvals{$num}:exists { + return False; + } else { + %dvals{$num} = 1; + } + } + + return True; +} + +my $range = 1 .. 500; +for $range.list -> $elem { + my @arr = prime-factors($elem); + my $retval = SquareFree(@arr); + if $retval { print("$elem ") }; +} + +say " "; diff --git a/challenge-150/robert-dicicco/ruby/ch-1.rb b/challenge-150/robert-dicicco/ruby/ch-1.rb new file mode 100644 index 0000000000..57459d2a14 --- /dev/null +++ b/challenge-150/robert-dicicco/ruby/ch-1.rb @@ -0,0 +1,32 @@ +#!ruby.exe + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Fibonacci Words (Ruby) + +a = '1234' +b = '5678' + +# recursive routine to create fibonacci series, but using strings + +def Fib ( first, second) + val = first + second + puts val + + # if new string length is less than 51, go another round using new combined string + if val.length < 51 then + Fib( second, val) + else + # return the string if length 51 or greater + return val + end + +end + +puts 'Fibonacci Words' +puts a +puts b + +# get the 51st character +char = Fib(a,b)[50].chr +puts "51st digit is " + char diff --git a/challenge-150/robert-dicicco/ruby/ch-2.rb b/challenge-150/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..970e737cb0 --- /dev/null +++ b/challenge-150/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,47 @@ +#!ruby.exe + +# Author: Robert DiCicco +# Date: 31-JAN-2022 +# Challenge 150 Square-Free Integer (Ruby) + +fsums = [] +LIMIT = 500 + +def factors(num) + arr = [] + (1..num).each do |f| + if num % f == 0 + arr.push(f) + end + end + + return arr +end + +def checkFactors(f) + f.each do |p| + next if p == 1 + if IsPerfectSquare(p) == true + return false + else + next + end + end + + return true +end + +def IsPerfectSquare(num) + Integer.sqrt(num) ** 2 == num +end + +(1..LIMIT).each do |num| + facarr = factors(num) + retval = checkFactors(facarr) + + if retval + fsums.push(num) + end +end + +puts "#{fsums}" |
