2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,17 +1,19 @@
|
|||
defmodule Random do
|
||||
defp generate_point(0, _, _, set), do: set
|
||||
defp generate_point(n, f, range, set) do
|
||||
defp generate_point(n, f, condition, set) do
|
||||
point = {x,y} = {f.(), f.()}
|
||||
if x*x + y*y in range and not Set.member?(set, point),
|
||||
do: generate_point(n-1, f, range, Set.put(set, point)),
|
||||
else: generate_point(n, f, range, set)
|
||||
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, HashSet.new)
|
||||
for x <- -15..15 do
|
||||
for y <- -15..15 do
|
||||
IO.write if Set.member?(points, {x,y}), do: "x", else: " "
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
defmodule Constrain do
|
||||
defp precalculate(range, condition) do
|
||||
for x <- range, y <- range, x*x + y*y in condition, do: {x,y}
|
||||
end
|
||||
|
||||
def circle do
|
||||
range = -15..15
|
||||
all_points = precalculate(range, 10*10..15*15)
|
||||
IO.puts length(all_points)
|
||||
points = Enum.shuffle(all_points) |> Enum.take(100)
|
||||
Enum.each(-15..15, fn x ->
|
||||
IO.puts Enum.map(range, fn y -> if Enum.member?(points, {x,y}), do: "o ", else: " " end)
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue