Skip to content

Instantly share code, notes, and snippets.

@neoneye
Last active February 4, 2021 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoneye/a26209b4b09dd2d06c1cb0a3b0aad99f to your computer and use it in GitHub Desktop.
Save neoneye/a26209b4b09dd2d06c1cb0a3b0aad99f to your computer and use it in GitHub Desktop.
Integer sequence A338277 generates a sunflower
items = []
values = Array.new(1000) do |i|
n = i + 2
x = (n ** 2) / 2
y = Integer.sqrt(x)
value = x % y
items << [n, x, y, value]
value
end
IO.write('a338277_values.csv', values.join("\n"))
rows = []
items.each do |n, x, y, value|
radians = value * Math::PI * 2 / y.to_f
px = Math::cos(radians) * n
py = Math::sin(radians) * n
rows << ("%.2f;%.2f" % [px, py])
end
IO.write('a338277_sunflower.csv', rows.join("\n"))
# See this plot: https://i.imgur.com/cVo5QdD.png
items = []
values = Array.new(10000) do |i|
n = i + 2
x = (n ** 2) / 2.0 # real numbers, where A338277 use integers
y = x ** 0.5 # real numbers, where A338277 use integers
value = x % y
items << [n, x, y, value]
value
end
IO.write('a338277_values.csv', values.join("\n"))
rows = []
items.each do |n, x, y, value|
radians = value * Math::PI * 2 / y.to_f
distance = n ** 0.5
px = Math::cos(radians) * distance
py = Math::sin(radians) * distance
rows << ("%.2f;%.2f" % [px, py])
end
IO.write('a338277_sunflower.csv', rows.join("\n"))
# See this plot: https://i.imgur.com/xVXGirJ.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment