functiona1_15(n)local p = 4.75; local tax = 0.03; local extra = 0.10;
local res = 4.74 * n
res = res * (1 + 0.03 + 0.10)
return res
endfunctiona1_20(n)local res;
res = n * 9 * 12345679print(9 * 12345679)
return res;
endfunctiona1_25a(n)local space, i, k, maxWidth;
i = 0; space = 0; maxWidth = n + n - 1;
while (i < n) do
space = (maxWidth - (i + i - 1)) // 2;
while (space > 0) doio.write(' '); space = space - 1; end
k = 0;
while (k < i) doio.write("*"); io.write(' '); k = k + 1; endprint();
i = i + 1;
endendfunctiona1_27()local s, e, n, d, m, o, r, y, n1, n2, n3;
m = 1for s = 0, 9dofor e = 0, 9dofor n = 0, 9dofor d = 0, 9dofor o = 0, 9dofor r = 0, 9dofor y = 0, 9do
n1 = 1000 * s + 100 * e + 10 * n + d;
n2 = 1000 * m + 100 * o + 10 * r + e;
n3 = 10000 * m + 1000 * 0 + 100 * n + 10 * e + y;
if ((d + e) % 10 == y and n1 + n2 == n3)
thenprint(n1 .. ' + ' .. n2 .. ' = ' .. n3);
-- return -- 有很多组结果endendendendendendendendendfunctiona1_29(a, b)local c, i; i = 0io.write(a .. ', ' .. b .. ', ')
while (i < 3) do
c = a * b; a = b; b = c; i = i + 1; io.write(c, ', ')
endendfunctiona1_30()local i; i = 1;
while (i < 7) doprint(i / 7); i = i + 1; endprint()
print(1/7);
io.write(' '); print(3/7);
print(2/7);
io.write(' '); print(6/7);
print(4/7);
io.write(' '); print(5/7);
endfunctiona1_30()local m;
m = 9485 // 4;
while (m < 9485and m * 4 - 74 - 23 - 86 ~= 9485) do m = m + 1; endprint(m)
return m
endfunctiona2()-- a ^ b == exp(b * ln(a))local a, b;
a = 5 ^ 8; -- ^ 是乘方
b = math.exp(8 * math.log(5)) -- 底数都是eprint(a)
print(b)
a = math.floor(a); b = math.floor(b); -- 竟然差1 说明四舍五入不同print(a, b)
a = math.tointeger(a); b = math.tointeger(b); -- 竟然差1 print(a, b)
print(math.tointeger(a) == math.tointeger(b))
end-- a2(2,3)functionStringEx()
s = "abcdef"for i = 1, 5doprint(string.sub(s, i));
print(string.sub(s, i, i))
print(string.byte(s, i))
endendfunctionplist(xs)
s = '{'for i = 1, #xs do
s = s .. xs[i]
if (i ~= #xs) then
s = s .. ', 'endend
s = s .. '}'print(s)
end
xs = {1, 2, 3}
plist(xs)
functionpermgen(a, n)if n == 0then
printResult(a)
elsefor i=1,n do-- put i-th element as the last one
a[n], a[i] = a[i], a[n]
-- generate all permutations of the other elements
permgen(a, n - 1)
-- restore i-th element
a[n], a[i] = a[i], a[n]
endendendfunctionprintResult(a)for i,v inipairs(a) doio.write(v, " ")
endio.write("\n")
end
permgen ({1,2,3,4}, 2)