aboutsummaryrefslogtreecommitdiff
path: root/src/syslua/test.lua
blob: 7c9989c8d8eae2f23252b3c0342c649738f10ef4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
print("Hello, world! (printed)")

local t = {}

function t.decomp(x)
	local ret = {}
	for i = 2, x do
		while x % i == 0 do
			table.insert(ret, i)
			x = x // i
		end
	end
	return ret
end

function t.pretty(n)
	for i = 1, n do
		local d = t.decomp(i)
		for _, v in pairs(d) do
			io.stdout:write(('-'):rep(v) .. ' ')
		end
		io.stdout:write('\n')
	end
end

function t.guess(n)
	local a = math.random(n)
	while true do
		io.stdout:write("Guess? ")
		local x = tonumber(io.stdin:read())
		if x < a then
			print("Too small!")
		elseif x > a then
			print("Too big!")
		else
			print("Bingo!")
			break
		end
	end
end

return t