Skip to content

Instantly share code, notes, and snippets.

@rgegriff
Created September 13, 2021 15:08
Show Gist options
  • Save rgegriff/99d2399536c8603d7ba23af4038c167a to your computer and use it in GitHub Desktop.
Save rgegriff/99d2399536c8603d7ba23af4038c167a to your computer and use it in GitHub Desktop.
def is_palindromatic(num):
'''returns true if passed int is palindromatic'''
return str(num) == str(num)[::-1]
# Demonstrating my lazi--- I mean ability to reuse code
def palingen():
'''go through all the ints, and yield the palindromatic ones'''
val = -1
while True:
val += 1
if is_palindromatic(val):
yield val
def stop_at_value(stop_val, gen):
'''stop returning values from a generator if value returned is greater than stop_val'''
while True:
val = gen.__next__()
if val < stop_val:
yield val
else:
return
answer = sum(stop_at_value(10000, palingen())) # => 545040
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment