diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-06-30 14:07:03 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-06-30 14:07:03 +0100 |
| commit | 2e7aba5bc7a20402ad27f7c8e7fcfabcb79559a7 (patch) | |
| tree | d3c1b676974bdacd55535f674367a791ef90fcc9 /challenge-275 | |
| parent | 7edec2d1810751b703297f27426a9629eb3076d0 (diff) | |
| download | perlweeklychallenge-club-2e7aba5bc7a20402ad27f7c8e7fcfabcb79559a7.tar.gz perlweeklychallenge-club-2e7aba5bc7a20402ad27f7c8e7fcfabcb79559a7.tar.bz2 perlweeklychallenge-club-2e7aba5bc7a20402ad27f7c8e7fcfabcb79559a7.zip | |
- Added solutions by Jan Krnavek.
- Added solutions by Nelo Tovar.
- Added solutions by Bruce Gray.
- Added solutions by Simon Green.
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-275')
| -rw-r--r-- | challenge-275/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-275/laurent-rosenfeld/perl/ch-2.pl | 19 | ||||
| -rw-r--r-- | challenge-275/laurent-rosenfeld/raku/ch-2.raku | 15 |
3 files changed, 35 insertions, 0 deletions
diff --git a/challenge-275/laurent-rosenfeld/blog.txt b/challenge-275/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..8976bea039 --- /dev/null +++ b/challenge-275/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2024/06/-perl-weekly-challenge-275-replace-digits.html diff --git a/challenge-275/laurent-rosenfeld/perl/ch-2.pl b/challenge-275/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..a546f33821 --- /dev/null +++ b/challenge-275/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,19 @@ +use strict; +use warnings; +use feature 'say'; + +sub replace_digits { + my @chars = split //, shift; + for my $i (1..$#chars) { + if ($chars[$i] =~ /\d/) { + $chars[$i] = chr( $chars[$i] + ord $chars[$i-1]); + } + } + return join "", @chars; +} + +my @tests = ('a1c1e1', 'a1b2c3d4', 'b2b', 'a16z'); +for my $test (@tests) { + printf "%-10s => ", $test; + say replace_digits $test; +} diff --git a/challenge-275/laurent-rosenfeld/raku/ch-2.raku b/challenge-275/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..2481d7dc1c --- /dev/null +++ b/challenge-275/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,15 @@ +sub replace-digits ($in) { + my @chars = $in.comb; + for 1..@chars.end -> $i { + if @chars[$i] ~~ /\d/ { + @chars[$i] = chr( @chars[$i-1].ord + @chars[$i]); + } + } + return join "", @chars; +} + +my @tests = 'a1c1e1', 'a1b2c3d4', 'b2b', 'a16z'; +for @tests -> $test { + printf "%-10s => ", $test; + say replace-digits $test; +} |
