Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Stopped using range from the Ruby version of iterate as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpedrosa committed Nov 19, 2011
1 parent eb42b8e commit 7251d73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions luhny.rb
Expand Up @@ -4,12 +4,11 @@
DIGITS = {'0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4,
'5' => 5, '6' => 6, '7' => 7, '8' => 8, '9' => 9}

def test_it a
a = a.map{|s| s.to_i }
def test_it a, startAt, maxLen
total = 0
doubleDigit = false
i = a.length - 1
while i >= 0
i = startAt + maxLen - 1
while i >= startAt
total += doubleDigit ? DOUBLE_DIGITS[a[i]] : a[i]
doubleDigit = !doubleDigit
i -= 1
Expand All @@ -26,22 +25,22 @@ def iterate s
n = 0
max_len = len > 16 ? 16 : len
while n + max_len - 1 < len do
result = test_it(s[n...n + max_len])
result = test_it(s, n, max_len)
if result
match_start = n
match_len = max_len
break
end
if max_len == 16
result = test_it(s[n...n + 15])
result = test_it(s, n, 15)
if result
match_start = n
match_len = 15
break
end
end
if max_len == 16 or max_len == 15
result = test_it(s[n...n + 14])
result = test_it(s, n, 14)
if result
match_start = n
match_len = 14
Expand Down
4 changes: 2 additions & 2 deletions mask.sh
Expand Up @@ -2,5 +2,5 @@

# Call your program here instead of cat.
#cat
#./luhny.rb
./luhny.dart
./luhny.rb
#./luhny.dart

0 comments on commit 7251d73

Please sign in to comment.