RosettaCodeData/Task/Pascals-triangle-Puzzle/Pluto/pascals-triangle-puzzle.pluto
2025-08-11 18:05:26 -07:00

19 lines
518 B
Text

local function is_integral(x, tol)
local frac = {math.modf(x)}[2]
return math.abs(frac) <= tol
end
local function pascal(a, b, mid, top)
local yd = (top - 4 * (a + b)) / 7
if !is_integral(yd, 0.0001) then return {0, 0, 0} end
local y = math.floor(yd)
local x = mid - 2 * a - y
return {x, y, y - x}
end
local sol = pascal(11, 4, 40, 151)
if sol[0] != 0 then
print(string.format("Solution is: x = %d, y = %d, z = %d", sol[1], sol[2], sol[3]))
else
print("There is no solution")
end