aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-10-19 20:13:33 +0200
committerAbigail <abigail@abigail.be>2021-10-19 20:25:58 +0200
commit210e271ec3014cf6f08e9ce5d3e2ffbd92a61619 (patch)
treec1cc76b4f9b6e317f74e96487de3cb9054e86acd
parentec0548d9d1f8f277a0cd78d5a626c4efdd42f3ef (diff)
downloadperlweeklychallenge-club-210e271ec3014cf6f08e9ce5d3e2ffbd92a61619.tar.gz
perlweeklychallenge-club-210e271ec3014cf6f08e9ce5d3e2ffbd92a61619.tar.bz2
perlweeklychallenge-club-210e271ec3014cf6f08e9ce5d3e2ffbd92a61619.zip
Last character of a SEDOL must be a number.
Without this check, it could validate the SEDOL which uses a letter as a check digit. For instance, if the check digit is a '1', using 'B' would validate as well.
-rw-r--r--challenge-135/abigail/awk/ch-2.awk1
-rw-r--r--challenge-135/abigail/bash/ch-2.sh2
-rw-r--r--challenge-135/abigail/c/ch-2.c3
-rw-r--r--challenge-135/abigail/lua/ch-2.lua6
-rw-r--r--challenge-135/abigail/node/ch-2.js4
-rw-r--r--challenge-135/abigail/perl/ch-2.pl5
-rw-r--r--challenge-135/abigail/python/ch-2.py2
-rw-r--r--challenge-135/abigail/ruby/ch-2.rb2
-rw-r--r--challenge-135/abigail/tcl/ch-2.tcl2
9 files changed, 19 insertions, 8 deletions
diff --git a/challenge-135/abigail/awk/ch-2.awk b/challenge-135/abigail/awk/ch-2.awk
index 021224dfe0..8da795ccf7 100644
--- a/challenge-135/abigail/awk/ch-2.awk
+++ b/challenge-135/abigail/awk/ch-2.awk
@@ -24,6 +24,7 @@ BEGIN {
#
/[^0-9BCDFGHJKLMNPQRSTVWXYZ]/ {print 0; next}
length ($0) != 7 {print 0; next}
+/[^0-9]$/ {print 0; next}
#
# Do the check sum
diff --git a/challenge-135/abigail/bash/ch-2.sh b/challenge-135/abigail/bash/ch-2.sh
index 0d4c43e705..d79226883a 100644
--- a/challenge-135/abigail/bash/ch-2.sh
+++ b/challenge-135/abigail/bash/ch-2.sh
@@ -17,6 +17,8 @@ do if ((${#line} != 7))
then echo 0
elif [[ $line =~ [^0-9BCDFGHJKLMNPQRSTVWXYZ] ]]
then echo 0
+ elif [[ $line =~ [^0-9]$ ]]
+ then echo 0
else
((check = 0))
for ((i = 0; i < 7; i ++))
diff --git a/challenge-135/abigail/c/ch-2.c b/challenge-135/abigail/c/ch-2.c
index ba49db177e..27295d6bc9 100644
--- a/challenge-135/abigail/c/ch-2.c
+++ b/challenge-135/abigail/c/ch-2.c
@@ -34,7 +34,8 @@ int main (void) {
line_ptr [i] != 'E' &&
line_ptr [i] != 'I' &&
line_ptr [i] != 'O' &&
- line_ptr [i] != 'U') {
+ line_ptr [i] != 'U' &&
+ i < 6) {
first = 'A';
base = 10;
}
diff --git a/challenge-135/abigail/lua/ch-2.lua b/challenge-135/abigail/lua/ch-2.lua
index e6b70b2830..d979fbe2a0 100644
--- a/challenge-135/abigail/lua/ch-2.lua
+++ b/challenge-135/abigail/lua/ch-2.lua
@@ -10,8 +10,12 @@
local w = {1, 3, 1, 7, 3, 9, 1}
+local valid = "[0-9BCDFGHJKLMNPQRSTVWXYZ]"
+local pat = "^" .. valid .. valid .. valid ..
+ valid .. valid .. valid .. "[0-9]$"
+
for line in io . lines () do
- if line : find ("^[0-9BCDFGHJKLMNPQRSTVWXYZ]*$") then
+ if line : find (pat) then
local check = 0
for i = 1, 7 do
local byte = string . byte (line : sub (i, i))
diff --git a/challenge-135/abigail/node/ch-2.js b/challenge-135/abigail/node/ch-2.js
index d1ef83492a..8085ca0f6b 100644
--- a/challenge-135/abigail/node/ch-2.js
+++ b/challenge-135/abigail/node/ch-2.js
@@ -14,7 +14,9 @@ let w = [1, 3, 1, 7, 3, 9, 1]
. createInterface ({input: process . stdin})
. on ('line', line => {
line = line . trim ()
- if (line . length != 7 || line . match (/[^0-9BCDFGHJKLMNPQRSTVWXYZ]/)) {
+ if (line . length != 7 ||
+ line . match (/[^0-9BCDFGHJKLMNPQRSTVWXYZ]/) ||
+ line . match (/[^0-9]$/)) {
console . log (0)
}
else {
diff --git a/challenge-135/abigail/perl/ch-2.pl b/challenge-135/abigail/perl/ch-2.pl
index 8fda269604..df6a3e18f6 100644
--- a/challenge-135/abigail/perl/ch-2.pl
+++ b/challenge-135/abigail/perl/ch-2.pl
@@ -35,8 +35,9 @@ my %c = do {my $c = 0; map {$_ => $c ++} 0 .. 9, 'A' .. 'Z'};
# except vowels; this is capture group 1.
# ((?1)): use the same subpattern as capture group 1,
# and capture it.
-# @{["((?1))" x 6]}: repeat the above 6 times.
+# @{["((?1))" x 5]}: repeat the above 5 times.
+# [0-9]: last character must be digit
#
-say /^((?[[0-9A-Z]-[AEIOU]]))@{["((?1))" x 6]}/x &&
+say /^((?[[0-9A-Z]-[AEIOU]]))@{["((?1))" x 5]}([0-9])$/x &&
($c {$1} + 3 * $c {$2} + $c {$3} + 7 * $c {$4} + 3 * $c {$5} + 9 * $c {$6} +
$c {$7}) % 10 == 0 || 0 while <>;
diff --git a/challenge-135/abigail/python/ch-2.py b/challenge-135/abigail/python/ch-2.py
index 93ba2921e2..13ab812ae0 100644
--- a/challenge-135/abigail/python/ch-2.py
+++ b/challenge-135/abigail/python/ch-2.py
@@ -15,7 +15,7 @@ w = [1, 3, 1, 7, 3, 9, 1]
for line in fileinput . input ():
line = line . strip ()
- if re . search (r'^[0-9BCDFGHJKLMNPQRSTVWXYZ]{7}$', line):
+ if re . search (r'^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$', line):
check = 0
for i in range (len (line)):
val = ord (line [i : i + 1])
diff --git a/challenge-135/abigail/ruby/ch-2.rb b/challenge-135/abigail/ruby/ch-2.rb
index e77981d64a..da2f131c28 100644
--- a/challenge-135/abigail/ruby/ch-2.rb
+++ b/challenge-135/abigail/ruby/ch-2.rb
@@ -13,7 +13,7 @@ w = [1, 3, 1, 7, 3, 9, 1]
ARGF . each_line do
| line |
line . strip!
- if line . match (/^[0-9BCDFGHJKLMNPQRSTVWXYZ]/) then
+ if line . match (/^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$/) then
check = 0
line . split('') . each_with_index do
| char, i |
diff --git a/challenge-135/abigail/tcl/ch-2.tcl b/challenge-135/abigail/tcl/ch-2.tcl
index 9df349e33b..045e1f2d07 100644
--- a/challenge-135/abigail/tcl/ch-2.tcl
+++ b/challenge-135/abigail/tcl/ch-2.tcl
@@ -9,7 +9,7 @@
set w {1 3 1 7 3 9 1}
while {[gets stdin line] >= 0} {
- if {[regexp {^[0-9BCDFGHJKLMNPQRSTVWXYZ]{7}$} $line]} {
+ if {[regexp {^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$} $line]} {
set check 0
for {set i 0} {$i < [string length $line]} {incr i} {
set val [scan [string index $line $i] %c]