summaryrefslogtreecommitdiff
path: root/lua/day2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/day2.lua')
-rw-r--r--lua/day2.lua79
1 files changed, 79 insertions, 0 deletions
diff --git a/lua/day2.lua b/lua/day2.lua
new file mode 100644
index 0000000..0526d78
--- /dev/null
+++ b/lua/day2.lua
@@ -0,0 +1,79 @@
+dofile("util.lua")
+
+ice_cream_scoops = {
+ "vanilla",
+ "chocolate";
+
+ sprinkles = true
+}
+
+greek_numbers = {
+ ena = "one",
+ dyo = "two",
+ tria = "three"
+}
+
+mt = {
+ __tostring = table_to_string
+}
+
+setmetatable(greek_numbers, mt)
+
+Villain = {
+ health = 100,
+
+ new = function(self, name)
+ obj = {
+ name = name,
+ health = self.health
+ }
+ setmetatable(obj, self)
+ self.__index = self
+ return obj
+ end,
+
+ take_hit = function(self)
+ self.health = self.health - 10
+ end
+}
+
+dietrich = Villain:new("Dietrich")
+
+SuperVillain = Villain:new()
+function SuperVillain:take_hit()
+ self.health = self.health - 5
+end
+
+joker = SuperVillain:new("Joker")
+
+function fibonacci()
+ local m = 1
+ local n = 1
+
+ while true do
+ coroutine.yield(m)
+ m, n = n, m+n
+ end
+end
+
+generator = coroutine.create(fibonacci)
+
+-- Easy
+function concatenate(a1, a2)
+ local new = {}
+ for i = 1, #a1 do
+ new[#new+1] = a1[i]
+ end
+ for i = 1, #a2 do
+ new[#new+1] = a2[i]
+ end
+ return new
+end
+
+l1 = {1,2,3}
+l2 = {4,5,6,7,8}
+
+-- Medium -- ????????????????????????????
+-- function _G.__add(self, v)
+-- return concatenate(self, v)
+-- end