summaryrefslogtreecommitdiff
path: root/080.py
blob: 9becd190d897e9ce4668950463c6e6c0b6d3a57f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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