Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
defmodule Random do
defp generate_point(0, _, _, set), do: set
defp generate_point(n, f, condition, set) do
point = {x,y} = {f.(), f.()}
if x*x + y*y in condition and not point in set,
do: generate_point(n-1, f, condition, MapSet.put(set, point)),
else: generate_point(n, f, condition, set)
end
def circle do
f = fn -> :rand.uniform(31) - 16 end
points = generate_point(100, f, 10*10..15*15, MapSet.new)
range = -15..15
for x <- range do
for y <- range do
IO.write if {x,y} in points, do: "x", else: " "
end
IO.puts ""
end
end
end
Random.circle

View file

@ -0,0 +1,14 @@
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