From f297364cb013e42a5e59c0c51f3231d6fe890ae1 Mon Sep 17 00:00:00 2001 From: Zeheng Li Date: Mon, 4 Dec 2023 15:19:39 -0700 Subject: [PATCH] add examples --- src/3dprinter.lua | 6 ++++++ src/addtwonumbers.lua | 2 ++ src/alexandbarb.lua | 7 +++++++ src/areal.lua | 2 ++ src/betting.lua | 3 +++ src/bossbattle.lua | 6 ++++++ src/crne.lua | 4 ++++ src/discdistrict.lua | 1 + src/gcd.lua | 6 ++++++ src/hradgreining.lua | 5 +++++ src/laptopsticker.lua | 6 ++++++ src/makingameowth.lua | 2 ++ src/nastyhacks.lua | 10 ++++++++++ src/overdraft.lua | 15 +++++++++++++++ src/pieceofcake2.lua | 2 ++ src/pizza2.lua | 2 ++ src/thanos.lua | 9 +++++++++ src/timeloop.lua | 3 +++ src/twostones.lua | 5 +++++ src/twosum.lua | 2 ++ src/whichisgreater.lua | 6 ++++++ 21 files changed, 104 insertions(+) create mode 100644 src/3dprinter.lua create mode 100644 src/addtwonumbers.lua create mode 100644 src/alexandbarb.lua create mode 100644 src/areal.lua create mode 100644 src/betting.lua create mode 100644 src/bossbattle.lua create mode 100644 src/crne.lua create mode 100644 src/discdistrict.lua create mode 100644 src/gcd.lua create mode 100644 src/hradgreining.lua create mode 100644 src/laptopsticker.lua create mode 100644 src/makingameowth.lua create mode 100644 src/nastyhacks.lua create mode 100644 src/overdraft.lua create mode 100644 src/pieceofcake2.lua create mode 100644 src/pizza2.lua create mode 100644 src/thanos.lua create mode 100644 src/timeloop.lua create mode 100644 src/twostones.lua create mode 100644 src/twosum.lua create mode 100644 src/whichisgreater.lua diff --git a/src/3dprinter.lua b/src/3dprinter.lua new file mode 100644 index 0000000..5dad31a --- /dev/null +++ b/src/3dprinter.lua @@ -0,0 +1,6 @@ +n = io.read("*n") +d = 1 +while 2 ^ (d - 1) < n do + d = d + 1 +end +print(d) diff --git a/src/addtwonumbers.lua b/src/addtwonumbers.lua new file mode 100644 index 0000000..5803eef --- /dev/null +++ b/src/addtwonumbers.lua @@ -0,0 +1,2 @@ +a, b = io.read("*n", "*n") +print(a + b) diff --git a/src/alexandbarb.lua b/src/alexandbarb.lua new file mode 100644 index 0000000..f0fa61f --- /dev/null +++ b/src/alexandbarb.lua @@ -0,0 +1,7 @@ +k, m, n = io.read("*n", "*n", "*n") + +if k % (m + n) < m then + print("Barb") +else + print("Alex") +end diff --git a/src/areal.lua b/src/areal.lua new file mode 100644 index 0000000..2c2b544 --- /dev/null +++ b/src/areal.lua @@ -0,0 +1,2 @@ +s = io.read("*n") +print(4 * math.sqrt(s)) diff --git a/src/betting.lua b/src/betting.lua new file mode 100644 index 0000000..90ec049 --- /dev/null +++ b/src/betting.lua @@ -0,0 +1,3 @@ +a = io.read("*n") +print(string.format("%.10f", 100 / a)) +print(string.format("%.10f", 100 / (100 - a))) diff --git a/src/bossbattle.lua b/src/bossbattle.lua new file mode 100644 index 0000000..869e2c6 --- /dev/null +++ b/src/bossbattle.lua @@ -0,0 +1,6 @@ +n = io.read("*n") +if n // 4 > 0 then + print(n - 2) +else + print(1) +end diff --git a/src/crne.lua b/src/crne.lua new file mode 100644 index 0000000..5fdf34f --- /dev/null +++ b/src/crne.lua @@ -0,0 +1,4 @@ +n = io.read("*n") +a = n // 2 +b = n - a +print((a + 1) * (b + 1)) diff --git a/src/discdistrict.lua b/src/discdistrict.lua new file mode 100644 index 0000000..1183479 --- /dev/null +++ b/src/discdistrict.lua @@ -0,0 +1 @@ +print(1, io.read()) diff --git a/src/gcd.lua b/src/gcd.lua new file mode 100644 index 0000000..40f7d0b --- /dev/null +++ b/src/gcd.lua @@ -0,0 +1,6 @@ +a, b = io.read("*n", "*n") +function gcd(a, b) + return b == 0 and a or gcd(b, a % b) +end + +print(gcd(a, b)) diff --git a/src/hradgreining.lua b/src/hradgreining.lua new file mode 100644 index 0000000..6036ebe --- /dev/null +++ b/src/hradgreining.lua @@ -0,0 +1,5 @@ +if string.find(io.read(), "COV") then + print("Veikur!") +else + print("Ekki veikur!") +end diff --git a/src/laptopsticker.lua b/src/laptopsticker.lua new file mode 100644 index 0000000..eb937e2 --- /dev/null +++ b/src/laptopsticker.lua @@ -0,0 +1,6 @@ +wc, hc, ws, hs = io.read("*n", "*n", "*n", "*n") +if wc - 2 >= ws and hc - 2 >= hs then + print(1) +else + print(0) +end diff --git a/src/makingameowth.lua b/src/makingameowth.lua new file mode 100644 index 0000000..a8b65af --- /dev/null +++ b/src/makingameowth.lua @@ -0,0 +1,2 @@ +n, p, x, y = io.read("*n", "*n", "*n", "*n") +print(p * x + p // (n - 1) * y) diff --git a/src/nastyhacks.lua b/src/nastyhacks.lua new file mode 100644 index 0000000..c2101e5 --- /dev/null +++ b/src/nastyhacks.lua @@ -0,0 +1,10 @@ +for _ = 1, io.read("*n") do + r, e, c = io.read("*n", "*n", "*n") + if e > r + c then + print("advertise") + elseif e < r + c then + print("do not advertise") + else + print("does not matter") + end +end diff --git a/src/overdraft.lua b/src/overdraft.lua new file mode 100644 index 0000000..9d4683e --- /dev/null +++ b/src/overdraft.lua @@ -0,0 +1,15 @@ +n = io.read("*n") +s = 0 +b = 0 +for _ = 1, n do + t = io.read("*n") + if t > 0 then + b = b + t + elseif b + t < 0 then + s = s - (b + t) + b = 0 + else + b = b + t + end +end +print(s) diff --git a/src/pieceofcake2.lua b/src/pieceofcake2.lua new file mode 100644 index 0000000..b0f3132 --- /dev/null +++ b/src/pieceofcake2.lua @@ -0,0 +1,2 @@ +n, h, v = io.read("*n", "*n", "*n") +print(4 * math.max(h * v, (n - h) * (n - v), h * (n - v), v * (n - h))) diff --git a/src/pizza2.lua b/src/pizza2.lua new file mode 100644 index 0000000..117527a --- /dev/null +++ b/src/pizza2.lua @@ -0,0 +1,2 @@ +r, c = io.read("*n", "*n") +print(string.format("%.6f", (r - c) ^ 2 / r ^ 2 * 100)) diff --git a/src/thanos.lua b/src/thanos.lua new file mode 100644 index 0000000..bd01831 --- /dev/null +++ b/src/thanos.lua @@ -0,0 +1,9 @@ +for _ = 1, io.read("*n") do + p, r, f = io.read("*n", "*n", "*n") + y = 0 + while p <= f do + p = p * r + y = y + 1 + end + print(y) +end diff --git a/src/timeloop.lua b/src/timeloop.lua new file mode 100644 index 0000000..6a1a8af --- /dev/null +++ b/src/timeloop.lua @@ -0,0 +1,3 @@ +for i = 1, io.read("*n") do + print(string.format("%d Abracadabra", i)) +end diff --git a/src/twostones.lua b/src/twostones.lua new file mode 100644 index 0000000..7c27860 --- /dev/null +++ b/src/twostones.lua @@ -0,0 +1,5 @@ +if io.read("*n") % 2 > 0 then + print("Alice") +else + print("Bob") +end diff --git a/src/twosum.lua b/src/twosum.lua new file mode 100644 index 0000000..5803eef --- /dev/null +++ b/src/twosum.lua @@ -0,0 +1,2 @@ +a, b = io.read("*n", "*n") +print(a + b) diff --git a/src/whichisgreater.lua b/src/whichisgreater.lua new file mode 100644 index 0000000..ff11684 --- /dev/null +++ b/src/whichisgreater.lua @@ -0,0 +1,6 @@ +a, b = io.read("*n", "*n") +if a > b then + print(1) +else + print(0) +end