Last active
May 20, 2018 17:33
-
-
Save dshemetov/b05a3034e35f3e66e20c2d33d5c39af0 to your computer and use it in GitHub Desktop.
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
(**First we make a function to obtain every spiral corner, then we interpolate between each corner to get the sides, sum together, and finally convert the bijection to an integer sequence.*)) | |
up = {0, 1}; | |
right = {1, 0}; | |
down = -up; | |
left = -right; | |
directions = {up, right, down, left}; | |
start = {0, 0}; | |
length = 100; | |
corners = Table[ | |
start + Sum[Ceiling[i/2] directions[[Mod[i, 4, 1]]], {i, 1, n}], | |
{n, 0, length}]; | |
Interpolate[a_, b_] := | |
Table[a + i (b - a)/Norm[b - a], {i, 1, Norm[b - a]}]; | |
spiral = Join[ | |
{{0, 0}}, | |
Join @@ | |
MapThread[Interpolate, {corners[[1 ;; -2]], corners[[2 ;;]]}] | |
]; | |
ListLinePlot[spiral, PlotLabel -> "Spiral Bijection"] | |
FindFrog[f_, t_] := f[[1]] t + f[[2]]; | |
frogSequence = MapThread[FindFrog, {spiral, Range[Length[spiral]]}]; | |
ListPlot[frogSequence, PlotLabel -> "Integer Sequence"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The output plots for convenience:
