diff options
| author | Solathian <horvath6@gmail.com> | 2023-11-05 20:51:27 +0100 |
|---|---|---|
| committer | Solathian <horvath6@gmail.com> | 2023-11-05 20:51:27 +0100 |
| commit | ef5caf159a754b6539cfcb5c9037669f1c43ecf5 (patch) | |
| tree | 18fc7d6829717197c5d93b3748a90b058a16039b /challenge-241 | |
| parent | 8b14b81403ee66b91e17cf5200ccaecc652d4036 (diff) | |
| download | perlweeklychallenge-club-ef5caf159a754b6539cfcb5c9037669f1c43ecf5.tar.gz perlweeklychallenge-club-ef5caf159a754b6539cfcb5c9037669f1c43ecf5.tar.bz2 perlweeklychallenge-club-ef5caf159a754b6539cfcb5c9037669f1c43ecf5.zip | |
Added files for 241!
Diffstat (limited to 'challenge-241')
| -rw-r--r-- | challenge-241/solathian/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-241/solathian/perl/ch-2.pl | 55 |
2 files changed, 85 insertions, 0 deletions
diff --git a/challenge-241/solathian/perl/ch-1.pl b/challenge-241/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..2d002c083a --- /dev/null +++ b/challenge-241/solathian/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!usr/bin/perl +use v5.38; + +# Challenge 241 - 1 - Arithmetic Triplets + +say art(3, 0, 1, 4, 6, 7, 10); +say art(2, 4, 5, 6, 7, 8, 9); + +sub art($diff, @nums) +{ + my $number; + + for(my $i = 0; $i < @nums - 2; $i++ ) + { + for(my $j = $i; $j < @nums - 1; $j++ ) + { + for(my $k = $j; $k < @nums; $k++ ) + { + + if( (($nums[$j] - $nums[$i]) == $diff ) && (($nums[$k] - $nums[$j]) == $diff )) + { + # say join(",", $nums[$i], $nums[$j], $nums[$k]); + $number++; + } + } + } + } + + return $number; +}
\ No newline at end of file diff --git a/challenge-241/solathian/perl/ch-2.pl b/challenge-241/solathian/perl/ch-2.pl new file mode 100644 index 0000000000..ac6c151973 --- /dev/null +++ b/challenge-241/solathian/perl/ch-2.pl @@ -0,0 +1,55 @@ +#!usr/bin/perl +use v5.38; + +# Challenge 241 - 2 - Prime Order + + +say primerOrder(11, 8, 27, 4); # 11, 4, 8, 27 + + +sub createPrimeArray($number) +{ + my @primes; + my $divisor = 2; + + + die"Number should be greater than 1" if($number < 2); + + while($number != 1) + { + unless ($number % $divisor ) + { + $number /= $divisor; + push(@primes, $divisor); + $divisor = 2; + } + else + { + $divisor++; + } + } + + return scalar @primes; +} + +sub primerOrder(@list) +{ + my %hash; # since the list is unique we can use a hash + my @result; + + foreach my $number (@list) + { + $hash{$number} = createPrimeArray($number); + } + + # sort by the number of primes, if equal, sort by the number + foreach my $key (sort {$hash{$a} <=> $hash{$b} || $a <=> $b } keys %hash) + { + push(@result, $key); + } + + # cause why not + $" = ', '; + "@result"; + +}
\ No newline at end of file |
