diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-12-06 16:09:24 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-06 16:09:24 +0000 |
| commit | 3b74ecd7407317544cb31c685284e5af6bdf4a2b (patch) | |
| tree | f48ad2aaca2e1266fa6a9e0495d1141d05fa6939 | |
| parent | c85117b835fc4d7af7514d9468156c79b2b7d559 (diff) | |
| parent | 98edabfa843b06bc8aa9246ee16de7f8f75e853e (diff) | |
| download | perlweeklychallenge-club-3b74ecd7407317544cb31c685284e5af6bdf4a2b.tar.gz perlweeklychallenge-club-3b74ecd7407317544cb31c685284e5af6bdf4a2b.tar.bz2 perlweeklychallenge-club-3b74ecd7407317544cb31c685284e5af6bdf4a2b.zip | |
Merge pull request #7216 from zapwai/branch-for-challenge-194
Week 194
| -rwxr-xr-x | challenge-194/zapwai/perl/ch-1.pl | 27 | ||||
| -rwxr-xr-x | challenge-194/zapwai/perl/ch-2.pl | 48 |
2 files changed, 75 insertions, 0 deletions
diff --git a/challenge-194/zapwai/perl/ch-1.pl b/challenge-194/zapwai/perl/ch-1.pl new file mode 100755 index 0000000000..e1dea11103 --- /dev/null +++ b/challenge-194/zapwai/perl/ch-1.pl @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +use feature 'say'; +my $time = $ARGV[0] || '?5:00'; +my @A = split ':', $time; +my @hh = split '', $A[0]; +my @mm = split '', $A[1]; +my $ans; +if ($hh[0] eq '?') { + if ($hh[1] < 4) { + $ans = 2; + } + else { + $ans = 1; + } +} elsif ($hh[1] eq '?') { + if ($hh[0] eq '2') { + $ans = 3; + } else { + $ans = 9; + } +} elsif ($mm[0] eq '?') { + $ans = 5; +} else { + $ans = 9; +} +say "Input: ".$time; +say "Output: ".$ans; diff --git a/challenge-194/zapwai/perl/ch-2.pl b/challenge-194/zapwai/perl/ch-2.pl new file mode 100755 index 0000000000..68ad934138 --- /dev/null +++ b/challenge-194/zapwai/perl/ch-2.pl @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +use feature 'say'; +my $s = $ARGV[0] || 'abac'; +my @word = split //, $s; +my @alph = split //, "abcdefghijklmnopqrstuvwxyz"; +my %hash = map { $_ => 0 } @alph; +foreach my $letter (@word) { + $hash{$letter}++; +} +my @freq; +my @letters; +my $letter; +foreach ( keys %hash ) { + if ($hash{$_} != 0) { + push @freq, $hash{$_}; + push @letters, $_; + } +} +say "Input: \$s = \'$s\'"; +my $ans; +$ans = "possible... remove $letter\n" if possible(); +print "Output: ".$ans; +if (!$ans) { + say "(Not possible.)" +} +sub possible { + my ($min, $max) = ($freq[0],$freq[0]); + foreach (1 .. $#freq) { + if ($freq[$_] < $min) { + $min = $freq[$_]; + } + if ($freq[$_] > $max) { + $max = $freq[$_]; + } + } + return 0 if (($max - $min > 1) || ($max - $min == 0)) ; + my $index; + my $index_counter = 0; + foreach (0 .. $#freq) { + if ($freq[$_] == $max) { + $index = $_; + $index_counter++; + } + return 0 if $index_counter > 1; + } + $letter = $letters[$index]; + return 1; +} |
