initial commit

This commit is contained in:
ergz 2023-03-24 15:59:23 -07:00
commit a0d8cd87b7
3 changed files with 49 additions and 0 deletions

25
eight-queen.lua Normal file
View File

@ -0,0 +1,25 @@
N = 8 -- size of the board
-- check whether position (n, c) is free from attacks
function is_place_ok (a, n, c)
for i = 1, n - 1 do -- leaving the inc/dec value empty defaults to +1
if (a[i] == c) or
(a[i] - i == c - n) or
(a[i] + i == c + n) then
return false
end
end
return true
end
function print_solution (a)
for i = 1, N, 1 do
for j = 1, N, 1 do
io.write(a[i] == j and "X" or "-", " ")
end
io.write("\n")
end
io.write("\n")
end

16
hello.lua Normal file
View File

@ -0,0 +1,16 @@
print("hello world!")
function fact (n)
if n < 0 then
print("factorial for a negative number is not defined!")
os.exit()m
elseif n == 0 then
return 1
else
return n * fact(n - 1)
end
end
print("enter a number")
a = io.read("*n")
print(fact(a))

8
lib1.lua Normal file
View File

@ -0,0 +1,8 @@
function norm (x, y)
return math.sqrt(x^2 + y^2)
end
function twice (x)
return 2.0 * x
end