From 033c392bcf37b969203ec5de979715a29e55e4a9 Mon Sep 17 00:00:00 2001 From: Aleks-Daniel Jakimenko-Aleksejev Date: Sun, 7 Apr 2019 22:00:55 +0300 Subject: My solutions for week 2 --- challenge-002/alexdaniel/perl6/ch-1.p6 | 9 +++++++++ challenge-002/alexdaniel/perl6/ch-2.p6 | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 challenge-002/alexdaniel/perl6/ch-1.p6 create mode 100644 challenge-002/alexdaniel/perl6/ch-2.p6 diff --git a/challenge-002/alexdaniel/perl6/ch-1.p6 b/challenge-002/alexdaniel/perl6/ch-1.p6 new file mode 100644 index 0000000000..a98b84fe71 --- /dev/null +++ b/challenge-002/alexdaniel/perl6/ch-1.p6 @@ -0,0 +1,9 @@ +# Supports any unicode digits, so ႐႐၄၂ will be trimmed to ၄၂. +# Zero and positive numbers are not trimmed because the task +# specifically asks for positive numbers. However, it is not specified +# what a “number” is, and same goes for formatting requirements (e.g. +# “.5“ vs “0.5”), therefore I decided to keep it simple and just do +# the integers. So it's just a neat example on how to do unicode-aware +# number matching. + +put S:r/^[ <:Nd> & <:Numeric_Value(0)> ]* +$>// for lines diff --git a/challenge-002/alexdaniel/perl6/ch-2.p6 b/challenge-002/alexdaniel/perl6/ch-2.p6 new file mode 100644 index 0000000000..ade157486b --- /dev/null +++ b/challenge-002/alexdaniel/perl6/ch-2.p6 @@ -0,0 +1,9 @@ +#| From base 10 to base 35 +sub postfix:<₃₅>(Real() $a) { $a.base: 35 } +#| From base 35 to base 10 +sub postfix:<₁₀>( Str() $a) { $a.parse-base: 35 } + +say ‘ALEXDANIEL’₁₀; +say 836407881643061₃₅; + +# You can do non-ints too, but they won't roundtrip as you might expect -- cgit