Monday, November 17, 2025

TWC348

Challenge Link

Task1

We split the string in half and count the vowels of each half:
#!/usr/bin/env perl
use strict;
use warnings;

sub string_alike{
  my $h = length($_[0]) / 2;
  my $a = (substr $_[0],0,$h) =~ tr/aeiouAEIOU//;
  my $b = (substr $_[0],$h) =~ tr/aeiouAEIOU//;
  $a == $b && $a != 0
}

printf "%d\n",string_alike('textbook');
printf "%d\n",string_alike('book');
printf "%d\n",string_alike('AbCdEfGh');
printf "%d\n",string_alike('rhythmmyth');
printf "%d\n",string_alike('UmpireeAudio')

Task2

We calculate the result by applying the given operations:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Show;

sub to_min{
  my @parts = split ':',$_[0];
  $parts[0] * 60 + $parts[1]
}

sub convert_time{
  my $diff = (to_min($_[1]) - to_min($_[0]) + 1440) % 1440;
  my $res = 0;
  foreach my $i(qw(60 15 5 1)) {
    $res += $diff / $i;
    $diff %= $i
  }
  $res
}

printf "%d\n",convert_time('02:30','02:45');
printf "%d\n",convert_time('11:55','12:15');
printf "%d\n",convert_time('09:00','13:00');
printf "%d\n",convert_time('23:45','00:30');
printf "%d\n",convert_time('14:20','15:25')

0 comments:

Post a Comment