Constrained random points on a circle: Difference between revisions

Content added Content deleted
(Added Kotlin)
Line 1,634: Line 1,634:


=={{header|Julia}}==
=={{header|Julia}}==
{{works with|Julia|0.6}}
This solution uses the "pick random x, y and cull" rather than the "calculate valid and choose randomly" approach.
This solution uses the "pick random x, y and cull" rather than the "calculate valid and choose randomly" approach.
<lang julia>function printcircle(lo::Integer, hi::Integer, ndots::Integer; pad::Integer = 2)
<lang Julia>
canvas = falses(2hi + 1, 2hi + 1)
const LO = 10
const HI = 15
i = 0
while i < ndots
const GOAL = 100
x, y = rand(-hi:hi, 2)

if lo ^ 2 - 1 < x ^ 2 + y ^ 2 < hi ^ 2 + 1
canvas = falses(2HI+1, 2HI+1)
canvas[x + hi + 1, y + hi + 1] = true
i = 0
i += 1

end
while i < GOAL
end
x = rand(-HI:HI)
y = rand(-HI:HI)
# print
LO^2-1 < x^2 + y^2 < HI^2+1 || continue
for i in 1:(2hi + 1)
row = map(j -> j ? "\u25cf " : " ", canvas[i, :])
i += 1
println(" " ^ pad, join(row))
canvas[x+HI+1, y+HI+1] = true
end
return canvas
end
end


printcircle(10, 15, 100)</lang>
for i in 1:(2HI+1)
println(" ", join(map(j -> j ? "\u25cf " : " ", canvas[i,:])))
end
</lang>


{{out}}
{{out}}