Created
February 7, 2018 13:09
-
-
Save seanballais/cf20d97dd0057058defdd6436da01bf2 to your computer and use it in GitHub Desktop.
Generates a number palindrome starting from 1 to a given length.
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
import sys | |
def horizontal_pyramid(current_value, limit): | |
if current_value == limit: | |
return str(current_value) | |
return str(current_value) + horizontal_pyramid(current_value + 1, limit) + str(current_value) | |
print(horizontal_pyramid(1, int(sys.argv[1]))) | |
# 1 -> '1' | |
# 2 -> '121' | |
# 3 -> '12321' | |
# ... and so on. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment