aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-135/cheok-yin-fung/julia/ch-1.jl46
-rw-r--r--challenge-135/cheok-yin-fung/perl/ch-2.pl2
2 files changed, 48 insertions, 0 deletions
diff --git a/challenge-135/cheok-yin-fung/julia/ch-1.jl b/challenge-135/cheok-yin-fung/julia/ch-1.jl
new file mode 100644
index 0000000000..164fee485c
--- /dev/null
+++ b/challenge-135/cheok-yin-fung/julia/ch-1.jl
@@ -0,0 +1,46 @@
+# The Weekly Challenge 135
+# Task 1 Middle 3-digits
+# Usage: include("ch-1.jl")
+
+function mid_three(x)
+ num = 0
+ if typeof(x) == Int64
+ num = x
+ else
+ try (
+ num = parse(Int64, x)
+ ) catch
+ return "Not an integer. / Format ill-suited."
+ end
+ end
+ num = num > 0 ? num : -num;
+ str = string(num)
+ len = length(str)
+ if len % 2 == 0
+ return "even number of digits"
+ else
+ if len < 3
+ return "too short"
+ end
+ end
+ m = convert(Int64,(len+1) // 2)
+ return str[m-1]*str[m]*str[m+1]
+end
+
+
+testcases = [1234567, -123, 1, 10, 14285, 33554432, 10737418240]
+
+for a in testcases
+ println(mid_three(a))
+end
+
+
+#=
+345
+123
+too short
+even number of digits
+428
+even number of digits
+741
+=#
diff --git a/challenge-135/cheok-yin-fung/perl/ch-2.pl b/challenge-135/cheok-yin-fung/perl/ch-2.pl
index 2b197fc888..3cb8ba1f83 100644
--- a/challenge-135/cheok-yin-fung/perl/ch-2.pl
+++ b/challenge-135/cheok-yin-fung/perl/ch-2.pl
@@ -9,6 +9,8 @@ say sedol($ARGV[0]) ? 1 : 0;
sub sedol {
return 0 if !defined($_[0]);
+ return 0 if $_[0] =~ m/[AEIOU]/;
+ return 0 if $_[0] !~ m/^[0-9B-Z]{7}$/;
my %val;
$val{$_} = $_ for (0..9);
$val{$_} = ord($_)-ord("A")+10 for ("A".."Z");