diff options
author | Guillermo Ramos | 2014-07-01 20:51:07 +0200 |
---|---|---|
committer | Guillermo Ramos | 2014-07-01 20:51:07 +0200 |
commit | f3c354d396a38033dac28ece6f6220e75cef5aec (patch) | |
tree | 98c0977e8152472463cd2947589f725c9d5e2551 /lua/day2.lua | |
parent | aef238a0600c5cb775bb371dbb2463fd0381bff9 (diff) | |
download | 7l-f3c354d396a38033dac28ece6f6220e75cef5aec.tar.gz |
[Lua] Día 2 (sin terminar)
Diffstat (limited to 'lua/day2.lua')
-rw-r--r-- | lua/day2.lua | 79 |
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 |