aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2023-04-24 14:28:32 -0400
committerDavid Ferrone <zapwai@gmail.com>2023-04-24 14:28:32 -0400
commitb0b0afd59d09807515f79edd6ce3d3cb24d1140c (patch)
treef0d0f50bf5ef798bc0efccfe9e2617acf9d4da8d
parent9df2d961ae00534346eaaceffaf8cfee4ecc88bb (diff)
downloadperlweeklychallenge-club-b0b0afd59d09807515f79edd6ce3d3cb24d1140c.tar.gz
perlweeklychallenge-club-b0b0afd59d09807515f79edd6ce3d3cb24d1140c.tar.bz2
perlweeklychallenge-club-b0b0afd59d09807515f79edd6ce3d3cb24d1140c.zip
Week 214
-rw-r--r--challenge-214/zapwai/perl/ch-1.pl64
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 "";