Generation of regular paper-folding sequence (dragon-curve) until a given number in Python
In mathematics the Regular paper folding sequence, also known as the Dragon curve sequence, is an infinite automatic sequence of 0s and 1s defined as the limit of the following process:
1 1 0
1 1 0 1 1 0 0
1 1 0 1 1 0 0 1 1 1 0 0 1 0 0
Dragon curves :
At each stage, an alternating sequence of 1s and 0s is inserted between the terms of the previous sequence. The sequence takes its name from the fact that it represents the sequence of left and right folds along a strip of paper that is folded repeatedly in half in the same direction. If each fold is then opened out to create a right-angled corner, the resulting shape approaches the dragon curve fractal. For instance, the following curve is given by folding a strip four times to the right and then unfolding to give right angles, this gives the first 15 terms of the sequence when 1 represents a right turn and 0 represents a left turn.
The paper folding sequence also satisfies the symmetry relation:
which shows that the paper folding word can be constructed as the limit of another iterated process as follows:
In each iteration of this process, a 1 is placed at the end of the previous iteration's string, then this string is repeated in reverse order, replacing 0 by 1 and vice versa.
n is an integer input taken in order to know the extent of the sequence
a list seq_start is defined with the initial element as 1
z is an integer to initialize the sequence
while iterating the sequence list we will append the sequence list along with 1 or 0 and reverse of the sequence
Submitted by Sheshagiri Kulkarni (sheshagiri)
Download packets of source code on Coders Packet