aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-002/alexdaniel/perl6/ch-1.p69
-rw-r--r--challenge-002/alexdaniel/perl6/ch-2.p69
2 files changed, 18 insertions, 0 deletions
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)> ]* <before <:Nd>+$>// 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