diff options
| -rwxr-xr-x | challenge-276/kai-burgdorf/perl/ch-2.pl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-276/kai-burgdorf/perl/ch-2.pl b/challenge-276/kai-burgdorf/perl/ch-2.pl new file mode 100755 index 0000000000..f314b182f7 --- /dev/null +++ b/challenge-276/kai-burgdorf/perl/ch-2.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +@ints = (1, 2, 2, 4, 1, 5); +#@ints = (1, 2, 3, 4, 5); + +my %frequencies; +my $highest = 0; +my $total = 0; + + +foreach (@ints) { + if (exists $frequencies{$_}) { + $frequencies{$_}++; + } + else { + $frequencies{$_} = 1; + } + if($frequencies{$_} > $highest) { + $highest=$frequencies{$_}; + } +} + +for(keys %frequencies){ + print("frequ for value $_ is $frequencies{$_}\n"); + if($frequencies{$_} == $highest) { + $total += $frequencies{$_}; + } +} + +print "\nhighest Frequency: $highest"; +print "\nOutput: $total"; |
