Anonymous user
Constrained random points on a circle: Difference between revisions
Constrained random points on a circle (view source)
Revision as of 14:41, 5 January 2018
, 6 years ago→{{header|Julia}}
(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)
if lo ^ 2 - 1 < x ^ 2 + y ^ 2 < hi ^ 2 + 1
▲canvas = falses(2HI+1, 2HI+1)
i += 1▼
end
▲while i < GOAL
end▼
▲ x = rand(-HI:HI)
▲ i += 1
println(" " ^ pad, join(row))
▲ canvas[x+HI+1, y+HI+1] = true
end
return canvas
end
printcircle(10, 15, 100)</lang>
▲ println(" ", join(map(j -> j ? "\u25cf " : " ", canvas[i,:])))
▲end
{{out}}
|