aboutsummaryrefslogtreecommitdiff
path: root/challenge-080/tyler-wardhaugh/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-080/tyler-wardhaugh/lua/ch-2.lua')
-rwxr-xr-xchallenge-080/tyler-wardhaugh/lua/ch-2.lua10
1 files changed, 3 insertions, 7 deletions
diff --git a/challenge-080/tyler-wardhaugh/lua/ch-2.lua b/challenge-080/tyler-wardhaugh/lua/ch-2.lua
index 54d355d037..2378d1b18b 100755
--- a/challenge-080/tyler-wardhaugh/lua/ch-2.lua
+++ b/challenge-080/tyler-wardhaugh/lua/ch-2.lua
@@ -4,14 +4,10 @@ local t2 = {}
function t2.count_candies(coll)
local count = #coll
- local maybe_inc = function(i, j)
- if (coll[i] > coll[j]) then count = count + 1 end
- end
- -- sweep left-to-right
- for i=1,#coll-1 do maybe_inc(i, i+1) end
- -- sweep right-to-left
- for i=#coll,2,-1 do maybe_inc(i, i-1) end
+ for i=1,#coll-1 do
+ if (coll[i] ~= coll[i+1]) then count = count + 1 end
+ end
return count
end