RosettaCodeData/Task/Constrained-random-points-on-a-circle/Elixir/constrained-random-points-on-a-circle-2.elixir

15 lines
398 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
defmodule Constrain do
def circle do
range = -15..15
r2 = 10*10..15*15
all_points = for x <- range, y <- range, x*x+y*y in r2, do: {x,y}
IO.puts "Precalculate: #{length(all_points)}"
points = Enum.take_random(all_points, 100)
Enum.each(range, fn x ->
IO.puts Enum.map(range, fn y -> if {x,y} in points, do: "o ", else: " " end)
end)
end
end
Constrain.circle