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
9 changes: 4 additions & 5 deletions challenge-341/ryan-thompson/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Ryan Thompson

## Week 301 Solutions
## Week 341 Solutions

### Task 1 › Largest Number
### Task 1 › Broken Keyboard

* [Perl](perl/ch-1.pl)

### Task 2 › Hamming Distance
### Task 2 › Reverse Prefix

* [Perl](perl/ch-2.pl)
* [C](c/ch-2.c)

## Blog

* [Hamming Distance and Large Numbers](https://ry.ca/2024/12/pwc-301-hamming-distance-and-large-numbers/)
* [Brken Keybard and Reverse Prefix](https://ry.ca/2025/10/brken-keybards-reverse-prefixes/)

## Tests

Expand Down
1 change: 1 addition & 0 deletions challenge-341/ryan-thompson/blog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://ry.ca/2025/10/brken-keybards-reverse-prefixes/
13 changes: 13 additions & 0 deletions challenge-341/ryan-thompson/perl/ch-1.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env perl

use v5.38;

# Upper/lowercase are usually on the same key, thus we ignore case
sub apssible { grep !/[@_\0]/i, split /\s+/, shift }
sub pssible {
#my $re = qr/[@_\0]/i;
#say STDERR $re;
grep !/[@_\0]/i, split /\s+/, shift
}

say join ' ', pssible(shift, @ARGV) if @ARGV
7 changes: 7 additions & 0 deletions challenge-341/ryan-thompson/perl/ch-2.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env perl

use v5.38;

sub rev_prefix { $_[0] =~ s/^(.+?\Q$_[1]\E)/reverse $1/er }

say rev_prefix(@ARGV) if @ARGV == 2;
26 changes: 26 additions & 0 deletions challenge-341/ryan-thompson/perl/t/ch-1.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!perl

require './ch-1.pl';

use Test2::V0;

# Scalar (count)
is pssible('Hello world', 'd' ), 1;
is pssible('apple banana cherry', 'a', 'e'), 0;
is pssible('Coding is fun', () ), 3;
is pssible('The Weekly Challenge', 'a', 'b'), 2;
is pssible('Perl and Python', 'p' ), 1;

# Array
is [pssible('Hello world', 'd' )], ['Hello'];
is [pssible('Foo bar baz', 'z' )], ['Foo', 'bar'];
is [pssible('All words impossible', 'l', 'd')], [ ];

# Degenerate
is pssible(''), 0;
is [pssible('')], [ ];

# hack3r! but not really.
ok dies { pssible('foo', 'a](?{ warn })[') };

done_testing;
19 changes: 19 additions & 0 deletions challenge-341/ryan-thompson/perl/t/ch-2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!perl

require './ch-2.pl';

use Test2::V0;

is rev_prefix(programming => 'g'), 'gorpramming';
is rev_prefix(hello => 'h'), 'hello',
is rev_prefix(abcdefghij => 'h'), 'hgfedcbaij';
is rev_prefix(reverse => 's'), 'srevere';
is rev_prefix(perl => 'r'), 'repl';

is rev_prefix('', ''), '';
is rev_prefix('a','a'), 'a';

# hack3r?
ok lives { rev_prefix('test', qr/(?{ die "u got pwned" })/) };

done_testing;