aboutsummaryrefslogtreecommitdiff
path: root/challenge-228/deadmarshal/lua/ch-1.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-228/deadmarshal/lua/ch-1.lua')
-rw-r--r--challenge-228/deadmarshal/lua/ch-1.lua18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-228/deadmarshal/lua/ch-1.lua b/challenge-228/deadmarshal/lua/ch-1.lua
new file mode 100644
index 0000000000..0de103fe4e
--- /dev/null
+++ b/challenge-228/deadmarshal/lua/ch-1.lua
@@ -0,0 +1,18 @@
+#!/usr/bin/env lua
+
+local function unique_sum(t)
+ local hash,sum = {},0
+ setmetatable(hash,{__index = function(t,k) return 0 end})
+ for i=1,#t do
+ hash[t[i]] = hash[t[i]] + 1
+ end
+ for k,v in pairs(hash) do
+ if v == 1 then sum = sum + k end
+ end
+ return sum
+end
+
+print(unique_sum({2,1,3,2}))
+print(unique_sum({1,1,1,1}))
+print(unique_sum({2,1,3,4}))
+