diff options
-rwxr-xr-x | lua/1.lua | 3 | ||||
-rwxr-xr-x | lua/2.lua | 15 | ||||
-rwxr-xr-x | lua/3.lua | 7 | ||||
-rwxr-xr-x | lua/4.lua | 38 | ||||
-rwxr-xr-x | lua/5.lua | 7 |
5 files changed, 70 insertions, 0 deletions
diff --git a/lua/1.lua b/lua/1.lua new file mode 100755 index 0000000..647dfd3 --- /dev/null +++ b/lua/1.lua @@ -0,0 +1,3 @@ +x = "Hello World!" + +print(x) diff --git a/lua/2.lua b/lua/2.lua new file mode 100755 index 0000000..a5a2374 --- /dev/null +++ b/lua/2.lua @@ -0,0 +1,15 @@ +function fact (n) + if n == 0 then + return 1 + else + return n * fact(n-1) + end +end + +print("enter a number: ") +a = io.read("*n") -- Read a number +if a < 0 then + print(a .. "negative") + return 1; +end +print(fact(a)) diff --git a/lua/3.lua b/lua/3.lua new file mode 100755 index 0000000..2106d37 --- /dev/null +++ b/lua/3.lua @@ -0,0 +1,7 @@ +function norm (x,y) + return math.sqrt(x^2+y^2); +end + +function twice(x) + return 2.0 * x; +end diff --git a/lua/4.lua b/lua/4.lua new file mode 100755 index 0000000..f965bc6 --- /dev/null +++ b/lua/4.lua @@ -0,0 +1,38 @@ +N = 8 + +function isPlaceOK(a,n,c) + for i = 1, n - 1 do + if (a[i] == c) or + (a[i] - n == c - n) or + (a[i] + n == c + n) then + return false; + end + end + return true; +end + +function printSolution(a) + for i = 1, N do + for j = 1, N do + io.write(a[i] == j and "X" or "-", ' '); + end + io.write('\n'); + end + io.write('\n'); +end + +function addQueen(a, n) + if n > N then + printSolution(a); + else + for c = 1, N do + if isPlaceOK(a,n,c) then + a[n] = c; + addQueen(a, n + 1); + end + end + end +end + + +addQueen({},1) diff --git a/lua/5.lua b/lua/5.lua new file mode 100755 index 0000000..eeeb25c --- /dev/null +++ b/lua/5.lua @@ -0,0 +1,7 @@ +local tolerance = 10; +function isturnback(angle) + angle = angle % 360; + return (math.abs(angle - 180) < tolerance) +end + +print(isturnback(-180)) |