Skip to content

Instantly share code, notes, and snippets.

@Ernir
Created December 9, 2014 11:10
Show Gist options
  • Save Ernir/1fd4d323e280989dce85 to your computer and use it in GitHub Desktop.
Save Ernir/1fd4d323e280989dce85 to your computer and use it in GitHub Desktop.
Skrítnar tölur
# Inefficient Python generator solution to:
# https://www.facebook.com/joladagatalnorda/posts/633189590143054 (Icelandic)
def funny_numbers():
n = 9 # No need to check single-digit numbers
while True:
n += 1
# Stringify for splitting
strung_n = str(n)
# Split
first, second = strung_n[:len(strung_n)/2], strung_n[len(strung_n)/2:]
# Check if condition is satisfied
if len(first) == len(second) and (int(first)+int(second))**2 == n:
yield n
# A few generated numbers
# 81
# 2025
# 3025
# 9801
# 494209
# 998001
# 24502500
# 25502500
# 52881984
# 60481729
@birkir
Copy link

birkir commented Dec 9, 2014

Yrði hraðvirkara með því að margfalda n með 10 ef hún er oddatala í len.
else n *= 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment