Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions challenge-341/vinod-k/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -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";
20 changes: 20 additions & 0 deletions challenge-341/vinod-k/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -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";
}
11 changes: 11 additions & 0 deletions challenge-341/vinod-k/python/ch-1.py
Original file line number Diff line number Diff line change
@@ -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}")
14 changes: 14 additions & 0 deletions challenge-341/vinod-k/python/ch-2.py
Original file line number Diff line number Diff line change
@@ -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}")