Last active
February 4, 2021 15:01
-
-
Save neoneye/a26209b4b09dd2d06c1cb0a3b0aad99f to your computer and use it in GitHub Desktop.
Integer sequence A338277 generates a sunflower
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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