Created
July 9, 2017 20:54
-
-
Save mlovci/df54e92459be337dca7b61ebadb9c227 to your computer and use it in GitHub Desktop.
A code poem.
This file contains 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
def serpentine(n_max): | |
# \ / | |
# Y | |
# # | |
# # | |
# # | |
# # | |
# # | |
# ## | |
# ##### | |
#""" #""" | |
## V V # | |
## T T # | |
## # | |
## * # | |
## =*= # | |
# # * # | |
# # # | |
b = -1 | |
i = 1 | |
j = 0 | |
k = 0 | |
while True: | |
if k <= 1: | |
i = 1 | |
k += 1 | |
elif b >= n_max-1: | |
if j == 1: | |
i = -1 | |
j = 0 | |
else: | |
j = 1 | |
i = 0 | |
elif b <= 0: | |
if j == 1: | |
i = 1 | |
j = 0 | |
else: | |
j = 1 | |
i = 0 | |
b += i | |
yield b | |
##### | |
#### | |
### | |
## | |
# | |
Author
mlovci
commented
Jul 9, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment