uppdateras med ojämna mellanrum

21 februari 2009

Problem #206, Concealed Square

Find the unique positive integer whose square has the form 1_2_3_4_5_6_7_8_9_0,
where each “_” is a single digit.
Det tog bara 7454 iterationer att brute forcea denna.
#!/usr/bin/env python
from math import sqrt

def match(a):
i = 10
while (a > 0):
a, i = a / 100, i - 1
if a % 10 != i:
return False
return True

n = int(sqrt(1929394959697989999)) + 1

while not match(n * n):
n = n - 1

print "Answer is", n
Oj, nu har melodifestivalen börjat. Ska vara lite social ett tag.

2 kommentarer:

Anonym sa...

he he den var ju busenkel...

Anonym sa...

Tack for intressant blogg

Om mig

Sundsvall, Sweden