diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-25 11:37:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-25 11:37:20 +0100 |
| commit | 2417c3e185db238b86b63bf33c33b398db7a358f (patch) | |
| tree | da1f35aa8c312fd19dd4f593ddbb0904192d8e62 | |
| parent | 0b58d3d4acc046547b3b8c0cce2f5ba9a0e7df2c (diff) | |
| parent | b0b0afd59d09807515f79edd6ce3d3cb24d1140c (diff) | |
| download | perlweeklychallenge-club-2417c3e185db238b86b63bf33c33b398db7a358f.tar.gz perlweeklychallenge-club-2417c3e185db238b86b63bf33c33b398db7a358f.tar.bz2 perlweeklychallenge-club-2417c3e185db238b86b63bf33c33b398db7a358f.zip | |
Merge pull request #7967 from zapwai/branch-for-214
Week 214
| -rw-r--r-- | challenge-214/zapwai/perl/ch-1.pl | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/challenge-214/zapwai/perl/ch-1.pl b/challenge-214/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..974552f6e0 --- /dev/null +++ b/challenge-214/zapwai/perl/ch-1.pl @@ -0,0 +1,64 @@ +use v5.30.0; +my @scores = (1,2,4,3,5); + +my @copy = @scores; +my %vals; + +$vals{$_} = 1 foreach (@scores); + +my @ordered_vals = keys %vals; +@ordered_vals = reverse sort @ordered_vals; +my @ranks; +for my $k (0 .. $#scores) { + foreach my $j (0 .. $#ordered_vals) { + $ranks[$k] = $j + 1 if ($scores[$k] == $ordered_vals[$j]); + } +} + +my ($one, $two, $tre); +foreach (0 .. $#ranks) { + if ($ranks[$_] == 1) { + $one++; + } elsif ($ranks[$_] == 2) { + $two++; + } elsif ($ranks[$_] == 3) { + $tre++; + } +} + +if ($one > 3) { + # Assign only gold + foreach (0 .. $#ranks) { + if ($ranks[$_] == 1) { + $ranks[$_] = "G"; + } + } +} elsif ( $one + $two >= 3 ) { + # assign gold and silver + foreach (0 .. $#ranks) { + if ($ranks[$_] == 1) { + $ranks[$_] = "G"; + } elsif ($ranks[$_] == 2) { + $ranks[$_] = "S"; + } + } +} else { + foreach (0 .. $#ranks) { + if ($ranks[$_] == 1) { + $ranks[$_] = "G"; + } elsif ($ranks[$_] == 2) { + $ranks[$_] = "S"; + } elsif ($ranks[$_] == 3) { + $ranks[$_] = "B"; + } + } + +} + +print "\@scores: "; +print foreach (@scores); +say ""; + +print "\@ranks : "; +print foreach (@ranks); +say ""; |
