diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-12-15 08:54:59 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-15 08:54:59 +0000 |
| commit | a1afd6c6b17b58e6c3b084ca4f0cf79b8059bb8d (patch) | |
| tree | bc252e22ebe562aa0e61b0c3eaf7110edb443f35 | |
| parent | c1d3932971f399789d4ee01cb886bb1e984f2563 (diff) | |
| parent | dbb7be7971d565a97f039fcaeb0def760c6f31ad (diff) | |
| download | perlweeklychallenge-club-a1afd6c6b17b58e6c3b084ca4f0cf79b8059bb8d.tar.gz perlweeklychallenge-club-a1afd6c6b17b58e6c3b084ca4f0cf79b8059bb8d.tar.bz2 perlweeklychallenge-club-a1afd6c6b17b58e6c3b084ca4f0cf79b8059bb8d.zip | |
Merge pull request #7255 from steve-g-lynn/branch-for-challenge-195
pwc 195
| -rw-r--r-- | challenge-195/steve-g-lynn/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/julia/ch-1.jl | 15 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/julia/ch-2.jl | 31 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/perl/ch-1.pl | 17 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/perl/ch-2.pl | 29 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/raku/ch-1.sh | 3 | ||||
| -rwxr-xr-x | challenge-195/steve-g-lynn/raku/ch-2.p6 | 14 |
7 files changed, 110 insertions, 0 deletions
diff --git a/challenge-195/steve-g-lynn/blog.txt b/challenge-195/steve-g-lynn/blog.txt new file mode 100644 index 0000000000..52e87873c3 --- /dev/null +++ b/challenge-195/steve-g-lynn/blog.txt @@ -0,0 +1 @@ +https://thiujiac.blogspot.com/2022/12/pwc-195.html diff --git a/challenge-195/steve-g-lynn/julia/ch-1.jl b/challenge-195/steve-g-lynn/julia/ch-1.jl new file mode 100755 index 0000000000..4d67db2003 --- /dev/null +++ b/challenge-195/steve-g-lynn/julia/ch-1.jl @@ -0,0 +1,15 @@ +#!/usr/bin/env julia + +function special_integers( n::Int64 ) ::Int64 + ctr=0 + for i in 1:n + if length(digits(i)) == length(unique(digits(i))) + ctr += 1 + end + end + return ctr +end + +println(special_integers(15)) +println(special_integers(35)) + diff --git a/challenge-195/steve-g-lynn/julia/ch-2.jl b/challenge-195/steve-g-lynn/julia/ch-2.jl new file mode 100755 index 0000000000..e83f504c80 --- /dev/null +++ b/challenge-195/steve-g-lynn/julia/ch-2.jl @@ -0,0 +1,31 @@ +#!/usr/bin/env julia + +using StatsBase + +function most_frequent_even( mylist::Vector{Int64} )::Int64 + evens = mylist[mylist .% 2 .== 0] + + if length(evens)==0 + return -1 + end + + d_freq = countmap(evens) #-- a dictionary (hash) + + max_freq=maximum(values(d_freq)) + + retval = Vector{Int64}() + + for i in keys(d_freq) + if d_freq[i] == max_freq + push!(retval, i) + end + end + + return minimum(retval) +end + + +println(most_frequent_even([1,1,2,6,2])) #2 +println(most_frequent_even([1,3,5,7])) #-1 +println(most_frequent_even([6,4,4,6,1])) #4 + diff --git a/challenge-195/steve-g-lynn/perl/ch-1.pl b/challenge-195/steve-g-lynn/perl/ch-1.pl new file mode 100755 index 0000000000..efec4b57db --- /dev/null +++ b/challenge-195/steve-g-lynn/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env -S perl -wl + +use List::MoreUtils qw(uniq); + +print &special_integers(15); #14 +print &special_integers(35); #32 + +sub special_integers { + my ($n)=@_; + + my $ctr=0; + for my $i (1 .. $n) { + my @n = uniq split(//,$i); + ($i == join('',@n)) && ($ctr++); + } + return $ctr; +} diff --git a/challenge-195/steve-g-lynn/perl/ch-2.pl b/challenge-195/steve-g-lynn/perl/ch-2.pl new file mode 100755 index 0000000000..a5c8f54ce1 --- /dev/null +++ b/challenge-195/steve-g-lynn/perl/ch-2.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env -S perl -wl + +use List::Util qw(min max); + +use strict; + +print &most_frequent_even((1,1,2,6,2)); #2 +print &most_frequent_even((1,3,5,7)); #-1 +print &most_frequent_even((6,4,4,6,1)); #4; + + +sub most_frequent_even { + + my (@list) = @_; + + (my @evens = grep {($_ % 2) == 0} @list ) || (return -1); + + my %bag; + for (@evens) { + $bag{$_}++; + } + + my $max_freq = max values %bag; + + @evens = grep {$bag{$_} == $max_freq} keys %bag; + + min @evens; + +} diff --git a/challenge-195/steve-g-lynn/raku/ch-1.sh b/challenge-195/steve-g-lynn/raku/ch-1.sh new file mode 100755 index 0000000000..23bf08d24c --- /dev/null +++ b/challenge-195/steve-g-lynn/raku/ch-1.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +raku -e '(1 .. @*ARGS[0]).grep({$_ == $_.comb.unique.join}).elems.say' $@ diff --git a/challenge-195/steve-g-lynn/raku/ch-2.p6 b/challenge-195/steve-g-lynn/raku/ch-2.p6 new file mode 100755 index 0000000000..f29bff6c37 --- /dev/null +++ b/challenge-195/steve-g-lynn/raku/ch-2.p6 @@ -0,0 +1,14 @@ +#!/usr/bin/env perl6 + +say &most-frequent-even((1,1,2,6,2)); #2 +say &most-frequent-even((1,3,5,7)); #-1 +say &most-frequent-even((6,4,4,6,1)); #4; + + +sub most-frequent-even (@list) { + (my @evens = @list.grep(* %% 2)) || (return -1); + + my $max-freq = @evens.Bag.values.max; + + @evens.Bag.pairs.grep({$_.value == $max-freq}).map({$_.key}).min; +} |
