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
1 change: 1 addition & 0 deletions challenge-348/peter-campbell-smith/blog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://ccgi.campbellsmiths.force9.co.uk/challenge/348
49 changes: 49 additions & 0 deletions challenge-348/peter-campbell-smith/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/perl

# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge

use v5.26; # The Weekly Challenge - 2025-11-17
use utf8; # Week 348 - task 1 - String alike
use warnings; # Peter Campbell Smith
binmode STDOUT, ':utf8';
use Encode;

string_alike('rhythm');
string_alike('artifice');
string_alike('MOONSOUP');
string_alike('fairzzzz');
string_alike('uu');
string_alike('aeioupaeioupaeiuopaeioupaeioupaeiuop');
string_alike('123+!£ a $#FF & U (]');

sub string_alike {

my ($string, $output, $size, $half, @count, $c, $h);

# initialise
$string = $_[0];
$output = 'false';
@count = (0, 0);

# check for even length
$size = length($string);
if (($size & 1) == 0) {
$half = $size / 2;
$h = 0;

# count vowels
for $c (0 .. $size - 1) {
$h = 1 if $c == $half;
$count[$h] ++ if substr($string, $c, 1) =~ m|[aeiou]|i;
}

# check for equality
if ($count[0] != 0 and $count[0] eq $count[1]) {
$output = qq[true - $count[0] vowel] . ($count[0] == 1 ? '' : 's');
}
}

say qq[\nInput: '$string'];
say qq[Output: $output];
}

45 changes: 45 additions & 0 deletions challenge-348/peter-campbell-smith/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/perl

# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge

use v5.26; # The Weekly Challenge - 2025-11-17
use utf8; # Week 348 - task 2 - Convert time
use warnings; # Peter Campbell Smith
binmode STDOUT, ':utf8';
use Encode;

convert_time('02:30', '02:45');
convert_time('11:55', '12:15');
convert_time('09:00', '13:00');
convert_time('23:45', '00:30');
convert_time('14:20', '15:25');
convert_time('00:00', '23:59');

sub convert_time {

my ($from, $till, @chunks, $from_mins, $till_mins, $gap, $j, $ops, $explain);

# initialise
($from, $till) = @_;
@chunks = (60, 15, 5, 1);
$explain = '';

# convert to minutes since midnight
$from_mins = substr($from, 0, 2) * 60 + substr($from, 3, 2);
$till_mins = substr($till, 0, 2) * 60 + substr($till, 3, 2);
$till_mins += 24 * 60 if $till_mins < $from_mins;
$gap = $till_mins - $from_mins;

# analyse difference
$ops = 0;
for $j (0 .. 3) {
while ($gap >= $chunks[$j]) {
$gap -= $chunks[$j];
$ops ++;
$explain .= qq[$chunks[$j] + ];
}
}

say qq[\nInput: \$source = '$from', \$target = '$till'];
say qq[Output: $ops : ] . substr($explain, 0, -2);
}