From 95341b61b030c9e1290f3b326cb7ec584f543aea Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Sun, 31 Aug 2014 20:21:45 +0200 Subject: moved files to higher directory after split to new repository --- 080.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 080.py (limited to '080.py') diff --git a/080.py b/080.py new file mode 100644 index 0000000..9becd19 --- /dev/null +++ b/080.py @@ -0,0 +1,55 @@ + +# schriftliches wurzelziehen: http://www.diaware.de/html/wurzel.html + +def sqrt(x, accuracy): + a = [] # vor komma + b = [] # nach komma + + groups = [] + while x > 0: + groups.append(x % 100) + x /= 100 + groups = groups[::-1] + + result = 0 + remainder = 0 + while accuracy > 0: + group = 100 * remainder + if len(groups) > 0: + group += groups[0] + + subcount = 0 + sub = 20*result + 1 + while sub < group: + group -= sub + if group < 0: + break + subcount += 1 + sub += 2 + remainder = group + if subcount == 0: + remainder *= 100 + result *= 10 + result += subcount + + if len(groups) > 0: + a.append(subcount) + del groups[0] + else: + b.append(subcount) + accuracy -= 1 + + return (a, b) + +squares = set([ x*x for x in range(11) ]) + +digitsum = 0 + +for n in xrange(100): + if n in squares: + continue + s = sqrt(n, 100) + digitsum += sum(s[0]) + sum(s[1]) + +print digitsum + -- cgit v1.2.3