Pascal's triangle/Puzzle: Difference between revisions

no edit summary
No edit summary
Line 1,548:
{{out}}
<pre>Solution: x = 5, y = 13, z = 8.</pre>
 
 
=={{header|Julia}}==
{{trans|Kotlin}}
<lang julia>struct Solution
x::Int
y::Int
z::Int
end
 
isIntegral(sol, atol) = (sol - floor(sol) <= atol) || (ceil(sol) - sol <= atol)
function pascal(a, b, mid, top)
yd = (top - 4 * (a + b)) / 7.0
!isIntegral(yd, 0.0001) && return Solution(0, 0, 0)
y = Int(round(yd))
x = mid - 2 * a - y
return Solution(x, y, y - x)
end
 
function testpascalpuzzle()
p = pascal(11, 4, 40, 151)
println(p.x != 0 ?
"Solution is: x = $(p.x), y = $(p.y), z = $(p.z)" :
"There is no solution.")
end
 
testpascalpuzzle()
</lang>{{out}}
<pre>
Solution is: x = 5, y = 13, z = 8
</pre>
 
=={{header|Kotlin}}==
4,105

edits