-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday23.txt
More file actions
106 lines (94 loc) · 3.7 KB
/
Copy pathday23.txt
File metadata and controls
106 lines (94 loc) · 3.7 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#################### ANNOTATED ASSEMBLY ####################
set b 65 # b = 65
set c b # c = 65
jnz a 2 # if a {
jnz 1 5 #
A: mul b 100 # mul_count += 1
sub b -100000 # b = 106500
set c b #
sub c -17000 # c = 123500
# }
# while true {
B: set f 1 # f = 1
set d 2 # d = 2
# do {
E: set e 2 # e = 2
D: set g d # do {
mul g e # mul_count += 1
sub g b #
jnz g 2 # if d * e == b {
set f 0 # f = 0
# }
C: sub e -1 # e++
set g e #
sub g b #
jnz g -8 # } while e != b
sub d -1 # d++
set g d #
sub g b #
jnz g -13 # } while d != b
jnz f 2 # if f == 0 {
sub h -1 # h++
# }
F: set g b #
sub g c #
jnz g 2 # if b == c {
jnz 1 3 # return
# }
G: sub b -17 # b += 17
jnz 1 -23 # }
#################### ANNOTATED C(ISH) ####################
b = 65 # if A:
c = 65 # b = 106500
if a { # c = b + 17000
mul_count += 1 # mul_count += 1
b = 106500 # else:
c = 123500 # b = c = 65
} #
while true { # for b in xrange(b, c + 1, 17):
f = 1 # f = 1
d = 2 # mul_count += (b - 2) ** 2
do { # for d in xrange(2, b):
e = 2 #
do { # for e in xrange(2, b):
mul_count += 1 #
if d * e == b { # if d * e == b:
f = 0 # f = 0
} #
e++ #
} while e != b #
d++ #
} while d != b #
if f == 0 { # if f == 0:
h++ # h += 1
} #
if b == c { #
return #
} #
b += 17 #
} #
#################### ANNOTATED PYTHON(ISH) ####################
if A:
b = 106500
c = b + 17000
mul_count += 1
else:
b = c = 65
for b in xrange(b, c + 1, 17): # h = len(filter(is_not_prime,
f = 1 # xrange(b, c + 1, 17)))
mul_count += (b - 2) ** 2 #
for d in xrange(2, b): #
for e in xrange(2, b): # mul_count = sum([
if d * e == b: # (i - 2) ** 2 for i in xrange(...)])
f = 0 #
if f == 0: #
h += 1 #
#################### ANSWERS ####################
Part 1: we just have one iteration, and are looking for mul_count, which is
(65 - 2) ** 2 = 63 ** 2 = 3969
Part 2: we are looking for the number of primes in the given range,
106500 to 123500 inclusive, going in steps of 17. 106500 is 17 * 6264 + 12, so
we are looking for any i from 6264 to 7264 inclusive such that 17i + 12 is
prime. The following mathematica command gives the answer:
In[1]:= Length[Select[17 * Range[6264, 7264] + 12, Not@*PrimeQ]]
Out[1]:= 917