luhnAlgorithmCheck 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/luhnAlgorithmCheck.rb +0 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14a651a6da2364b65591174f8f5a2fd4b807d6a654be5220ce72823dcf082cde
|
4
|
+
data.tar.gz: a0967eedefc4945ae1a59fd977d7a35982c80397e6d30a0da623c4d8bb7d3bc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d8c2fbb3351bced290e60f1a4b758cdf80769be044afe5ca232dace7b4fa759e50af6c58699836a612247ed0201cee23ad2d96a1f9972c320680eb2c2245076
|
7
|
+
data.tar.gz: f4b855fbb2649dfe769de44b35d3825de2607013e92a05a6148decfc291c29ba8193cefb8361e5c09e9c6fb05af28459611358b893335cdbd0015b19c6d5355e
|
data/lib/luhnAlgorithmCheck.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# Reference for below code taken from https://exercism.io/tracks/ruby/exercises/luhn/solutions/d9add5655baa476fb4f97bfa91645112
|
2
1
|
class LuhnAlgorithm
|
3
2
|
attr_reader :num
|
4
3
|
|
@@ -26,23 +25,6 @@ class LuhnAlgorithm
|
|
26
25
|
return possible.num if possible.valid?
|
27
26
|
end
|
28
27
|
end
|
29
|
-
|
30
|
-
# This function is not part of original logic referred from https://exercism.io/tracks/ruby/exercises/luhn/solutions/d9add5655baa476fb4f97bfa91645112
|
31
|
-
# This function is surplus logic referred from http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers
|
32
|
-
def luhn_valid?(str)
|
33
|
-
str.scan(/\d/).reverse #using str.to_i.digits fails for cases with leading zeros
|
34
|
-
.each_slice(2)
|
35
|
-
.sum { |i, k = 0| i.to_i + ((k.to_i)*2).digits.sum }
|
36
|
-
.modulo(10).zero?
|
37
|
-
end
|
38
|
-
|
39
|
-
# This function is not part of original logic referred from https://exercism.io/tracks/ruby/exercises/luhn/solutions/d9add5655baa476fb4f97bfa91645112
|
40
|
-
# This function is surplus logic referred from https://medium.com/@akshaymohite/luhns-algorithm-to-validate-credit-debit-card-numbers-1952e6c7a9d0
|
41
|
-
def luhn_algo_valid
|
42
|
-
number.reverse.split("").each_slice(2) do |x,y|
|
43
|
-
sum += x.to_i + (2*y.to_i).divmod(10).sum
|
44
|
-
end
|
45
|
-
end
|
46
28
|
|
47
29
|
private
|
48
30
|
def raw_addends
|