aboutsummaryrefslogtreecommitdiff
path: root/challenge-195
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-17 08:55:57 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-12-17 08:55:57 +0000
commit354f57ebd708492f1c50b05c6df41b894b795492 (patch)
tree4dbbe4da094e0323105ae260a2b5a91d139ebf75 /challenge-195
parent5731bf1ef565c72dd4fcd9ffee2a12513a078c97 (diff)
downloadperlweeklychallenge-club-354f57ebd708492f1c50b05c6df41b894b795492.tar.gz
perlweeklychallenge-club-354f57ebd708492f1c50b05c6df41b894b795492.tar.bz2
perlweeklychallenge-club-354f57ebd708492f1c50b05c6df41b894b795492.zip
- Added solutions by Robbie Hatley.
- Added solutions by Jorg Sommrey. - Added solutions by Robert DiCicco.
Diffstat (limited to 'challenge-195')
-rw-r--r--challenge-195/robert-dicicco/julia/ch-2.jl75
-rw-r--r--challenge-195/robert-dicicco/perl/ch-2.pl71
2 files changed, 146 insertions, 0 deletions
diff --git a/challenge-195/robert-dicicco/julia/ch-2.jl b/challenge-195/robert-dicicco/julia/ch-2.jl
new file mode 100644
index 0000000000..d60f58b273
--- /dev/null
+++ b/challenge-195/robert-dicicco/julia/ch-2.jl
@@ -0,0 +1,75 @@
+Challenge 195 Most Frequent Even ( Julia )
+
+#!/usr/bin/env julia
+
+#=
+
+AUTHOR: Robert DiCicco
+
+DATE : 2022-12-14
+
+Challenge 195 Most Frequent Even ( Julia )
+
+
+SAMPLE OUTPUT
+
+julia .\MFE.jl
+
+Input: @list = [1, 1, 2, 6, 2]
+
+Output: 2
+
+
+Input: @list = [1, 3, 5, 7]
+
+Output: -1
+
+
+Input: @list = [6, 4, 4, 6, 1]
+
+Output: 4
+
+-------------------------------------------------
+
+=#
+
+using Printf
+
+
+nn = [[1,1,2,6,2], [1,3,5,7], [6,4,4,6,1]]
+
+
+for n in nn
+
+ seen = Dict()
+
+ @printf("Input: @list = %s\n", n )
+
+ for x in n
+
+ if (x % 2 == 0) && (x > 1)
+
+ (haskey(seen,x)) ? (seen[x] += 1) : (seen[x] = 1)
+
+ end
+
+ end
+
+ if length(seen) > 0
+
+ val = first(sort(collect(seen), by = x->x[1]))
+
+ @printf("Output: %d\n\n",val[1])
+
+ else
+
+ println("Output: -1\n")
+
+ end
+
+end
diff --git a/challenge-195/robert-dicicco/perl/ch-2.pl b/challenge-195/robert-dicicco/perl/ch-2.pl
new file mode 100644
index 0000000000..1d359e103d
--- /dev/null
+++ b/challenge-195/robert-dicicco/perl/ch-2.pl
@@ -0,0 +1,71 @@
+#!/usr/bin/env perl
+
+=begin pod
+
+AUTHOR: Robert DiCicco
+
+DATE : 2022-12-14
+
+Challenge 195 Most Frequent Even ( Perl )
+
+
+SAMPLE OUTPUT
+
+perl MFE.pl
+
+Input: [1 1 2 6 2]
+
+Output: 2
+
+
+Input: [1 3 5 7]
+
+Output: -1
+
+
+Input: [6 4 4 6 1]
+
+Output: 4
+
+-----------------------------------------------
+
+=cut
+
+use strict;
+
+use warnings;
+
+use feature qw/say/;
+
+
+my @nn = ([1,1,2,6,2], [1,3,5,7], [6,4,4,6,1] );
+
+
+for my $n (@nn) {
+
+ my %seen = ();
+
+ print("Input: [@$n]\n");
+
+ foreach my $x (@$n) {
+
+ next if ($x =~ /^\d*[13579]$/);
+
+ (exists $seen{$x}) ? ($seen{$x}++) : ($seen{$x} = 1);
+
+ }
+
+ if ((keys %seen) == 0) {print"Output: -1\n\n";next;}
+
+
+ my @heights = reverse(sort { $seen{$a} <=> $seen{$b} } keys %seen);
+
+ print("Output: $heights[0]\n\n");
+
+}