Created
December 9, 2014 11:10
-
-
Save Ernir/1fd4d323e280989dce85 to your computer and use it in GitHub Desktop.
Skrítnar tölur
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yrði hraðvirkara með því að margfalda n með 10 ef hún er oddatala í len.
else n *= 10