aboutsummaryrefslogtreecommitdiff
path: root/challenge-101/paulo-custodio/lua
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
committer冯昶 <seaker@qq.com>2021-03-15 18:18:09 +0800
commit5ed25077fde85262036c9db3e893d70ae0907b5c (patch)
tree8932d25b3fa6076e2d91ab2a331d4d8bfff20544 /challenge-101/paulo-custodio/lua
parent8b6be37fe4dac8b4c6489a95e55514b76b298d15 (diff)
parent65d54d52500028ec5359a7d39619803ade281543 (diff)
downloadperlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.gz
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.bz2
perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-101/paulo-custodio/lua')
-rw-r--r--challenge-101/paulo-custodio/lua/ch-1.lua18
-rw-r--r--challenge-101/paulo-custodio/lua/ch-2.lua10
2 files changed, 14 insertions, 14 deletions
diff --git a/challenge-101/paulo-custodio/lua/ch-1.lua b/challenge-101/paulo-custodio/lua/ch-1.lua
index 7eac6f60f5..602143d1ee 100644
--- a/challenge-101/paulo-custodio/lua/ch-1.lua
+++ b/challenge-101/paulo-custodio/lua/ch-1.lua
@@ -8,10 +8,10 @@ Submitted by: Stuart Little
You are given an array @A of items (integers say, but they can be anything).
-Your task is to pack that array into an MxN matrix spirally counterclockwise,
+Your task is to pack that array into an MxN matrix spirally counterclockwise,
as tightly as possible.
-‘Tightly’ means the absolute value |M-N| of the difference has to be as small
+‘Tightly’ means the absolute value |M-N| of the difference has to be as small
as possible.
--]]
@@ -44,7 +44,7 @@ function build_empty_rectangle(m, n)
local rect = {}
for r=1, m do
rect[r] = {}
- for c=1, n do
+ for c=1, n do
rect[r][c] = ""
end
end
@@ -67,7 +67,7 @@ function spiral(numbers)
i = i + 1
c = c + 1
end
- c = c - 1
+ c = c - 1
r = r - 1
-- go North
while r >= 1 do
@@ -77,7 +77,7 @@ function spiral(numbers)
i = i + 1
r = r - 1
end
- r = r + 1
+ r = r + 1
c = c - 1
-- go West
while c >= 1 do
@@ -87,7 +87,7 @@ function spiral(numbers)
i = i + 1
c = c - 1
end
- c = c + 1
+ c = c + 1
r = r + 1
-- go South
while r <= m do
@@ -97,13 +97,13 @@ function spiral(numbers)
i = i + 1
r = r + 1
end
- r = r - 1
+ r = r - 1
c = c + 1
end
-
+
-- print result
for r=1, m do
- for c=1, n do
+ for c=1, n do
io.write(rect[r][c])
end
io.write("\n")
diff --git a/challenge-101/paulo-custodio/lua/ch-2.lua b/challenge-101/paulo-custodio/lua/ch-2.lua
index 47a12b657e..54b02aa59d 100644
--- a/challenge-101/paulo-custodio/lua/ch-2.lua
+++ b/challenge-101/paulo-custodio/lua/ch-2.lua
@@ -5,10 +5,10 @@ Challenge 101
TASK #2 › Origin-containing Triangle
Submitted by: Stuart Little
-You are given three points in the plane, as a list of six co-ordinates:
+You are given three points in the plane, as a list of six co-ordinates:
A=(x1,y1), B=(x2,y2) and C=(x3,y3).
-Write a script to find out if the triangle formed by the given three
+Write a script to find out if the triangle formed by the given three
co-ordinates contain origin (0,0).
Print 1 if found otherwise 0.
@@ -24,12 +24,12 @@ function point_in_triangle(xp,yp, x1,y1,x2,y2,x3,y3)
local d3 = sign(xp,yp, x3,y3, x1,y1)
local has_neg
- if (d1 < 0) or (d2 < 0) or (d3 < 0) then
+ if (d1 < 0) or (d2 < 0) or (d3 < 0) then
has_neg = true
else
has_neg = false
end
-
+
local has_neg = (d1 < 0) or (d2 < 0) or (d3 < 0)
local has_pos = (d1 > 0) or (d2 > 0) or (d3 > 0)
@@ -40,7 +40,7 @@ function point_in_triangle(xp,yp, x1,y1,x2,y2,x3,y3)
end
end
-io.write(point_in_triangle(0,0,
+io.write(point_in_triangle(0,0,
tonumber(arg[1]), tonumber(arg[2]),
tonumber(arg[3]), tonumber(arg[4]),
tonumber(arg[5]), tonumber(arg[6])), "\n")