summaryrefslogtreecommitdiff
path: root/080.py
diff options
context:
space:
mode:
authorReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:21:45 +0200
committerReiner Herrmann <reiner@reiner-h.de>2014-08-31 20:35:09 +0200
commit95341b61b030c9e1290f3b326cb7ec584f543aea (patch)
tree852386fa04d32eb859bca11c0eff7b5ef9e50f00 /080.py
parent571164d977f91925c4c76a292f74f5f93d09ae23 (diff)
moved files to higher directory after split to new repositoryHEADtrunk
Diffstat (limited to '080.py')
-rw-r--r--080.py55
1 files changed, 55 insertions, 0 deletions
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
+