Skip to content

Commit 2acd992

Browse files
authored
Merge pull request #12786 from rjt-pl/master
rjt's Week 341 solutions, blog, and tests
2 parents 776302e + acee7b8 commit 2acd992

File tree

6 files changed

+70
-5
lines changed

6 files changed

+70
-5
lines changed

challenge-341/ryan-thompson/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
# Ryan Thompson
22

3-
## Week 301 Solutions
3+
## Week 341 Solutions
44

5-
### Task 1 › Largest Number
5+
### Task 1 › Broken Keyboard
66

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

9-
### Task 2 › Hamming Distance
9+
### Task 2 › Reverse Prefix
1010

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

1413
## Blog
1514

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

1817
## Tests
1918

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://ry.ca/2025/10/brken-keybards-reverse-prefixes/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env perl
2+
3+
use v5.38;
4+
5+
# Upper/lowercase are usually on the same key, thus we ignore case
6+
sub apssible { grep !/[@_\0]/i, split /\s+/, shift }
7+
sub pssible {
8+
#my $re = qr/[@_\0]/i;
9+
#say STDERR $re;
10+
grep !/[@_\0]/i, split /\s+/, shift
11+
}
12+
13+
say join ' ', pssible(shift, @ARGV) if @ARGV
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env perl
2+
3+
use v5.38;
4+
5+
sub rev_prefix { $_[0] =~ s/^(.+?\Q$_[1]\E)/reverse $1/er }
6+
7+
say rev_prefix(@ARGV) if @ARGV == 2;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!perl
2+
3+
require './ch-1.pl';
4+
5+
use Test2::V0;
6+
7+
# Scalar (count)
8+
is pssible('Hello world', 'd' ), 1;
9+
is pssible('apple banana cherry', 'a', 'e'), 0;
10+
is pssible('Coding is fun', () ), 3;
11+
is pssible('The Weekly Challenge', 'a', 'b'), 2;
12+
is pssible('Perl and Python', 'p' ), 1;
13+
14+
# Array
15+
is [pssible('Hello world', 'd' )], ['Hello'];
16+
is [pssible('Foo bar baz', 'z' )], ['Foo', 'bar'];
17+
is [pssible('All words impossible', 'l', 'd')], [ ];
18+
19+
# Degenerate
20+
is pssible(''), 0;
21+
is [pssible('')], [ ];
22+
23+
# hack3r! but not really.
24+
ok dies { pssible('foo', 'a](?{ warn })[') };
25+
26+
done_testing;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!perl
2+
3+
require './ch-2.pl';
4+
5+
use Test2::V0;
6+
7+
is rev_prefix(programming => 'g'), 'gorpramming';
8+
is rev_prefix(hello => 'h'), 'hello',
9+
is rev_prefix(abcdefghij => 'h'), 'hgfedcbaij';
10+
is rev_prefix(reverse => 's'), 'srevere';
11+
is rev_prefix(perl => 'r'), 'repl';
12+
13+
is rev_prefix('', ''), '';
14+
is rev_prefix('a','a'), 'a';
15+
16+
# hack3r?
17+
ok lives { rev_prefix('test', qr/(?{ die "u got pwned" })/) };
18+
19+
done_testing;

0 commit comments

Comments
 (0)