Constrained random points on a circle: Difference between revisions

(Added Kotlin)
Line 1,634:
 
=={{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.
<lang julia>function printcircle(lo::Integer, hi::Integer, ndots::Integer; pad::Integer = 2)
<lang Julia>
canvas = falses(2HI2hi + 1, 2HI2hi + 1)
const LO = 10
const HI i = 150
while i < GOALndots
const GOAL = 100
x, y = rand(-HIhi:HIhi, 2)
 
if lo ^ 2 - 1 < x ^ 2 + y ^ 2 < hi ^ 2 + 1
canvas = falses(2HI+1, 2HI+1)
canvas[x +HI hi + 1, y +HI hi + 1] = true
i = 0
i += 1
 
end
while i < GOAL
end
x = rand(-HI:HI)
y# = rand(-HI:HI)print
LO^2-1for <i x^2in 1:(2hi + y^2 < HI^2+1 || continue)
println(" ",row = join(map(j -> j ? "\u25cf " : " ", canvas[i, :])))
i += 1
println(" " ^ pad, join(row))
canvas[x+HI+1, y+HI+1] = true
end
return canvas
end
 
printcircle(10, 15, 100)</lang>
for i in 1:(2HI+1)
println(" ", join(map(j -> j ? "\u25cf " : " ", canvas[i,:])))
end
</lang>
 
{{out}}
Anonymous user