diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-10-05 19:54:09 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-05 19:54:09 +0100 |
| commit | 579a115d1e4077fc13d23b7cac0590d0cf5a574d (patch) | |
| tree | c43c06e9a99bc5ff9dd97d6ab55c26e6026496be | |
| parent | 5fab196df6e7f6fa45ed577811baa3d5176443b4 (diff) | |
| parent | 39aa246c606877d74f601d39f68ac35fda3ea1ff (diff) | |
| download | perlweeklychallenge-club-579a115d1e4077fc13d23b7cac0590d0cf5a574d.tar.gz perlweeklychallenge-club-579a115d1e4077fc13d23b7cac0590d0cf5a574d.tar.bz2 perlweeklychallenge-club-579a115d1e4077fc13d23b7cac0590d0cf5a574d.zip | |
Merge pull request #12788 from vinodk89/branch-for-challenge-341
Solutions for Challenge-341
| -rw-r--r-- | challenge-341/vinod-k/perl/ch-1.pl | 30 | ||||
| -rw-r--r-- | challenge-341/vinod-k/perl/ch-2.pl | 20 | ||||
| -rw-r--r-- | challenge-341/vinod-k/python/ch-1.py | 11 | ||||
| -rw-r--r-- | challenge-341/vinod-k/python/ch-2.py | 14 |
4 files changed, 75 insertions, 0 deletions
diff --git a/challenge-341/vinod-k/perl/ch-1.pl b/challenge-341/vinod-k/perl/ch-1.pl new file mode 100644 index 0000000000..f4adb28be7 --- /dev/null +++ b/challenge-341/vinod-k/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +# Read sentence from standard input +print("Enter the sentence:\n"); +chomp(my $str = <STDIN>); + +# Read broken keys as space-separated input from standard input +print("Enter the broken keys as space-separated:\n"); +chomp(my $keys_line = <STDIN>); +my @keys = split /\s+/, $keys_line; + +my %broken = map { lc($_) => 1 } @keys; +my @words = split /\s+/, $str; + +my $count = 0; +foreach my $word (@words) { + my $can_type = 1; + foreach my $char (split //, lc($word)) { + if ($broken{$char}) { + $can_type = 0; + last; + } + } + $count++ if $can_type; +} + +print "$count\n"; diff --git a/challenge-341/vinod-k/perl/ch-2.pl b/challenge-341/vinod-k/perl/ch-2.pl new file mode 100644 index 0000000000..234a9c0709 --- /dev/null +++ b/challenge-341/vinod-k/perl/ch-2.pl @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +print "Enter the string: "; +chomp(my $str = <STDIN>); + +print "Enter the character to reverse prefix until: "; +chomp(my $char = <STDIN>); + +my $index = index($str, $char); + +if ($index == -1 || $index == 0) { + print "$str\n"; +} else { + my $prefix = substr($str, 0, $index + 1); + my $reversed = reverse $prefix; + print $reversed . substr($str, $index + 1) . "\n"; +} diff --git a/challenge-341/vinod-k/python/ch-1.py b/challenge-341/vinod-k/python/ch-1.py new file mode 100644 index 0000000000..2a2c08228e --- /dev/null +++ b/challenge-341/vinod-k/python/ch-1.py @@ -0,0 +1,11 @@ +sentence = input("Enter the sentence: ") +keys_input = input("Enter the broken keys separated by space: ") + +broken_keys = set(keys_input.lower().split()) + +count = 0 +for word in sentence.split(): + if all(char not in broken_keys for char in word.lower()): + count += 1 + +print(f"Number of words that can be typed: {count}") diff --git a/challenge-341/vinod-k/python/ch-2.py b/challenge-341/vinod-k/python/ch-2.py new file mode 100644 index 0000000000..c9cb239502 --- /dev/null +++ b/challenge-341/vinod-k/python/ch-2.py @@ -0,0 +1,14 @@ +input_str = input("Enter the string: ") +char = input("Enter the character to reverse prefix until: ") + +index = input_str.find(char) + +if index == -1 or index == 0: + # No change if character not found or at start + result = input_str +else: + prefix = input_str[:index+1] + rest = input_str[index+1:] + result = prefix[::-1] + rest + +print(f"Resulting string: {result}") |
