initial commit
This commit is contained in:
commit
a0d8cd87b7
|
@ -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
|
||||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue