diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2020-11-29 16:38:41 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2023-03-23 18:03:38 +0100 |
| commit | 2468dc495b4c86fc75545db923bfed3e1bbb5f6e (patch) | |
| tree | dfa118dd045cbe4288e69546767be0fa15f56acc /challenge-002 | |
| parent | b77c84eff9f4ea807e9da14a0c2899091643b3a5 (diff) | |
| download | perlweeklychallenge-club-2468dc495b4c86fc75545db923bfed3e1bbb5f6e.tar.gz perlweeklychallenge-club-2468dc495b4c86fc75545db923bfed3e1bbb5f6e.tar.bz2 perlweeklychallenge-club-2468dc495b4c86fc75545db923bfed3e1bbb5f6e.zip | |
Challenge 002 task 2
Diffstat (limited to 'challenge-002')
| -rw-r--r-- | challenge-002/jo-37/perl/ch-2.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-002/jo-37/perl/ch-2.pl b/challenge-002/jo-37/perl/ch-2.pl new file mode 100644 index 0000000000..d10ceb7280 --- /dev/null +++ b/challenge-002/jo-37/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl + +use Test2::V0; +use Math::Utils 'moduli'; +use List::Util 'reduce'; + +my @b35 = (0 .. 9, 'A' .. 'Y'); +my %b35 = map {($b35[$_] => $_)} 0 .. $#b35; + +sub to_b35 { + join '', map $b35[$_], reverse moduli(shift, 35); +} + +sub from_b35 { + reduce {$a * 35 + $b35{$b}} 0, split //, shift; +} + +is to_b35(0), '0'; +is to_b35(9), '9'; +is to_b35(10), 'A'; +is to_b35(34), 'Y'; +is to_b35(35), '10'; +is from_b35(to_b35(7**$_)), 7**$_ for 1 .. 18; + +done_testing; |
