Felix's average: 25 3/4
Delphine's average: 24.75 (which was lower than Felix's)
Program Output:
Felix
1,7,9,86 with average 25 3/4
1,6,9,87 with average 25 3/4
1,6,7,89 with average 25 3/4
6,7,9,81 with average 25 3/4
Delphine
1,6,9,83 with average 24.75
1,3,9,86 with average 24.75
1,3,6,89 with average 24.75
3,6,9,81 with average 24.75
7,9,24,86 with average 31.5
6,9,24,87 with average 31.5
6,7,24,89 with average 31.5
7,9,26,84 with average 31.5
4,9,26,87 with average 31.5
4,7,26,89 with average 31.5
6,9,27,84 with average 31.5
4,9,27,86 with average 31.5
4,6,27,89 with average 31.5
6,7,29,84 with average 31.5
4,7,29,86 with average 31.5
4,6,29,87 with average 31.5
8,9,42,67 with average 31.5
7,9,42,68 with average 31.5
7,8,42,69 with average 31.5
8,9,47,62 with average 31.5
2,9,47,68 with average 31.5
2,8,47,69 with average 31.5
7,9,48,62 with average 31.5
2,9,48,67 with average 31.5
2,7,48,69 with average 31.5
7,8,49,62 with average 31.5
2,8,49,67 with average 31.5
2,7,49,68 with average 31.5
----------------------------------
import math
from itertools import permutations
print('Felix')
for p in permutations('123456789'):
if int(p[7]) >= int(p[8]):
continue
if math.gcd(int(p[8]),int(p[7])) != 1:
continue
a = int(p[1])
b = 10*int(p[2])+int(p[3])
c = int(p[4])
d = int(p[5])
if a>c or a>d or c>d:
continue
avg = 10*int(p[0])+int(p[6]) + int(p[7])/int(p[8])
if avg == (a+b+c+d)/4:
print('{},{},{},{} with average {} {}/{}'.format(a,c,d,b,10*int(p[0])+int(p[6]),int(p[7]),int(p[8]) ))
print('Delphine')
for p in permutations('123456789'):
a = int(p[1])
b = 10*int(p[2])+int(p[3])
c = int(p[4])
d = int(p[5])
if a>c or a>d or c>d:
continue
avg = 10*int(p[0])+int(p[6]) + int(p[7])/10 +int(p[8])/100
if avg == (a+b+c+d)/4:
print('{},{},{},{} with average {}.{}{}'.format(a,c,d,b,10*int(p[0])+int(p[6]),int(p[7]),int(p[8]) ))
for p in permutations('123456789'):
a = 10*int(p[0])+int(p[1])
b = 10*int(p[2])+int(p[3])
c = int(p[4])
d = int(p[5])
if a>b or c>d:
continue
avg = 10*int(p[6]) + int(p[7]) + int(p[8])/10
if avg == (a+b+c+d)/4:
print('{},{},{},{} with average {}.{}'.format(c,d,a,b,10*int(p[6])+int(p[7]), int(p[8]) ))
|
Posted by Larry
on 2023-10-07 11:43:15 |