Skip to content

Instantly share code, notes, and snippets.

@seanballais
Created February 7, 2018 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seanballais/cf20d97dd0057058defdd6436da01bf2 to your computer and use it in GitHub Desktop.
Save seanballais/cf20d97dd0057058defdd6436da01bf2 to your computer and use it in GitHub Desktop.
Generates a number palindrome starting from 1 to a given length.
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