Skip to content

Commit ad24708

Browse files
committed
exercises were actually on chap0 so far
1 parent a96ae44 commit ad24708

File tree

2 files changed

+93
-93
lines changed

2 files changed

+93
-93
lines changed

math/how_to_prove_it/chap0.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
1. a) 3 as factor, so 2³-1, which give us 7. the other is 32767/7=4681
2+
b) 2³²⁷⁶⁷-1, so 7 is a factor. 2⁷-1=127
3+
4+
2) Suppose n is an integer greater than 1, 3^n-1 is even.
5+
6+
3)
7+
a) 2,3,5,7 so
8+
M=2x3x5x7+1=211
9+
10+
b) 2,5,11
11+
M=2x3x5x7x11+1=2311
12+
13+
4)
14+
```python
15+
isprime = lambda x: all(x%y!=0 for y in range(2,x))
16+
17+
primes = []
18+
for n in range(10000):
19+
if len(primes) == 5: break
20+
if isprime(n): primes.clear()
21+
else: primes.append(n)
22+
23+
primes
24+
[24, 25, 26, 27, 28]
25+
```
26+
27+
5)
28+
from the table, 3 and 7 are valid options, so 28 and 8128 as perfect
29+
30+
as an extra exercise, continuing the table:
31+
32+
n | isPrime | 2^n-1 | is 2^n-1 prime? |
33+
--|---------|-------|-----------------|
34+
11| yes | 2047 | no |
35+
12| no | 4095 | no |
36+
13| yes | 8191 | yes |
37+
14| no | 16383 | no |
38+
15| no | 32767 | no |
39+
16| no | 65535 | no |
40+
17| yes | 131071| yes |
41+
42+
candidates are 8191 and 131071
43+
from Euclid, 2^(n-1)*(2^n-1) is perfect, so
44+
33550336 and 8589869056
45+
46+
```python
47+
perfect = lambda x: 2**(x-1)*(2**x-1)
48+
isperfect = lambda x: x == sum(i for i in range(1, x) if x%i==0)
49+
for x in range(1,13):
50+
print(x, isprime(x), 2**x-1, isprime(2**x-1), perfect(x), isperfect(perfect(x)))```
51+
```
52+
53+
output:
54+
```
55+
1 True 1 True 1 False
56+
2 True 3 True 6 True
57+
3 True 7 True 28 True
58+
4 False 15 False 120 False
59+
5 True 31 True 496 True
60+
6 False 63 False 2016 False
61+
7 True 127 True 8128 True
62+
8 False 255 False 32640 False
63+
9 False 511 False 130816 False
64+
10 False 1023 False 523776 False
65+
11 True 2047 False 2096128 False
66+
12 False 4095 False 8386560 False
67+
```
68+
69+
6)
70+
```python
71+
for n in range(1, 30000):
72+
if isprime(n) and isprime(n+2) and isprime(n+4):
73+
print(n, n+2, n+4)
74+
```
75+
```
76+
1 3 5
77+
3 5 7
78+
```
79+
up to 30,000 those are the only 2 triplets
80+
81+
7)
82+
```python
83+
small_div_sum = lambda x: sum(n for n in range(1, x) if x%n==0)
84+
amicables = lambda x, y: small_div_sum(x) == y and small_div_sum(y) == x
85+
amicables(220, 284)
86+
amicables(20, 30)
87+
```
88+
89+
--->
90+
```
91+
True
92+
False
93+
```

math/how_to_prove_it/chap1.md

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +0,0 @@
1-
1. a) 3 as factor, so 2³-1, which give us 7. the other is 32767/7=4681
2-
b) 2³²⁷⁶⁷-1, so 7 is a factor. 2⁷-1=127
3-
4-
2) Suppose n is an integer greater than 1, 3^n-1 is even.
5-
6-
3)
7-
a) 2,3,5,7 so
8-
M=2x3x5x7+1=211
9-
10-
b) 2,5,11
11-
M=2x3x5x7x11+1=2311
12-
13-
4)
14-
```python
15-
isprime = lambda x: all(x%y!=0 for y in range(2,x))
16-
17-
primes = []
18-
for n in range(10000):
19-
if len(primes) == 5: break
20-
if isprime(n): primes.clear()
21-
else: primes.append(n)
22-
23-
primes
24-
[24, 25, 26, 27, 28]
25-
```
26-
27-
5)
28-
from the table, 3 and 7 are valid options, so 28 and 8128 as perfect
29-
30-
as an extra exercise, continuing the table:
31-
32-
n | isPrime | 2^n-1 | is 2^n-1 prime? |
33-
--|---------|-------|-----------------|
34-
11| yes | 2047 | no |
35-
12| no | 4095 | no |
36-
13| yes | 8191 | yes |
37-
14| no | 16383 | no |
38-
15| no | 32767 | no |
39-
16| no | 65535 | no |
40-
17| yes | 131071| yes |
41-
42-
candidates are 8191 and 131071
43-
from Euclid, 2^(n-1)*(2^n-1) is perfect, so
44-
33550336 and 8589869056
45-
46-
```python
47-
perfect = lambda x: 2**(x-1)*(2**x-1)
48-
isperfect = lambda x: x == sum(i for i in range(1, x) if x%i==0)
49-
for x in range(1,13):
50-
print(x, isprime(x), 2**x-1, isprime(2**x-1), perfect(x), isperfect(perfect(x)))```
51-
```
52-
53-
output:
54-
```
55-
1 True 1 True 1 False
56-
2 True 3 True 6 True
57-
3 True 7 True 28 True
58-
4 False 15 False 120 False
59-
5 True 31 True 496 True
60-
6 False 63 False 2016 False
61-
7 True 127 True 8128 True
62-
8 False 255 False 32640 False
63-
9 False 511 False 130816 False
64-
10 False 1023 False 523776 False
65-
11 True 2047 False 2096128 False
66-
12 False 4095 False 8386560 False
67-
```
68-
69-
6)
70-
```python
71-
for n in range(1, 30000):
72-
if isprime(n) and isprime(n+2) and isprime(n+4):
73-
print(n, n+2, n+4)
74-
```
75-
```
76-
1 3 5
77-
3 5 7
78-
```
79-
up to 30,000 those are the only 2 triplets
80-
81-
7)
82-
```python
83-
small_div_sum = lambda x: sum(n for n in range(1, x) if x%n==0)
84-
amicables = lambda x, y: small_div_sum(x) == y and small_div_sum(y) == x
85-
amicables(220, 284)
86-
amicables(20, 30)
87-
```
88-
89-
--->
90-
```
91-
True
92-
False
93-
```

0 commit comments

Comments
 (0)