Skip to content

Instantly share code, notes, and snippets.

@metasta
Last active March 15, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasta/a426d3c572151a197e532bc6197c5e59 to your computer and use it in GitHub Desktop.
Save metasta/a426d3c572151a197e532bc6197c5e59 to your computer and use it in GitHub Desktop.
比がなるべく1に近い2つの指数表現を探す問題

手習(比が1に近い2つの指数表現)

指数表現((a/b)c の形で表される数)に関する数学パズルを Python で強引に解く.

問題

a,b,c,d,e,f は 1 以上 10 以下の相異なる整数とする.
(a/b)c / (d/e)f ができるだけ 1 に近くなる a,b,c,d,e,f を求めよ.

(元の問題: "Simplifying Exponential Expressions" https://twitter.com/hyuki/status/1105380734699679744

解答

Python で全 10P6 通り(=151200 通り)をすべて計算した.
解答は以下の 40 通りあり, すべて 1 に等しい.

(6/3)10 / (4/1)5 = 1
(3/6)10 / (1/4)5 = 1
(4/1)5 / (6/3)10 = 1
(1/4)5 / (3/6)10 = 1
(6/3)10 / (8/2)5 = 1
(3/6)10 / (2/8)5 = 1
(8/2)5 / (6/3)10 = 1
(2/8)5 / (3/6)10 = 1
(10/5)6 / (4/1)3 = 1
(5/10)6 / (1/4)3 = 1
(4/1)3 / (10/5)6 = 1
(1/4)3 / (5/10)6 = 1
(10/5)6 / (8/2)3 = 1
(5/10)6 / (2/8)3 = 1
(8/2)3 / (10/5)6 = 1
(2/8)3 / (5/10)6 = 1
(4/2)9 / (8/1)3 = 1
(2/4)9 / (1/8)3 = 1
(8/1)3 / (4/2)9 = 1
(1/8)3 / (2/4)9 = 1
(10/5)6 / (8/1)2 = 1
(5/10)6 / (1/8)2 = 1
(8/1)2 / (10/5)6 = 1
(1/8)2 / (5/10)6 = 1
(10/5)9 / (8/1)3 = 1
(5/10)9 / (1/8)3 = 1
(8/1)3 / (10/5)9 = 1
(1/8)3 / (5/10)9 = 1
(6/2)8 / (9/1)4 = 1
(2/6)8 / (1/9)4 = 1
(9/1)4 / (6/2)8 = 1
(1/9)4 / (2/6)8 = 1
(6/2)10 / (9/1)5 = 1
(2/6)10 / (1/9)5 = 1
(9/1)5 / (6/2)10 = 1
(1/9)5 / (2/6)10 = 1
(3/2)10 / (9/4)5 = 1
(2/3)10 / (4/9)5 = 1
(9/4)5 / (3/2)10 = 1
(4/9)5 / (2/3)10 = 1

解説

任意の a,b,c,d,e,f について, (a/b)c / (d/e)f = (e/d)f / (b/a)c が成り立つ(単純な例:2/3 = (1/3)/(1/2)).
また, X/Y = 1 なら Y/X = 1 である.
したがって, (a/b)c / (d/e)f = 1 が成り立つとき
(b/a)c / (e/d)f = 1,
(d/e)f / (a/b)c = 1,
(e/d)f / (b/a)c = 1
はすべて成り立つ.
上記の 40 通りにこれらが含まれることを考慮すると, 解答は以下の 4 型, 計 10 通りに大別される.

第 1 型: 「4n = 22n」型(4 通り)

(4/1)3 / (10/5)6 = 1
(4/1)5 / (6/3)10 = 1
(8/2)3 / (10/5)6 = 1
(8/2)5 / (6/3)10 = 1

第 2 型: 「8n = 23n」型(3 通り)

(8/1)2 / (10/5)6 = 1
(8/1)3 / (4/2)9 = 1
(8/1)3 / (10/5)9 = 1

第 3 型: 「9n = 32n」型(2 通り)

(9/1)4 / (6/2)8 = 1
(9/1)5 / (6/2)10 = 1

第 4 型: 「(9/4)n = (3/2)2n」型(1 通り)

(9/4)5 / (3/2)10 = 1

余談

その1: ぴったり 1 にはならないが最も 1 に近い答は

(8/2)1 / (7/6)9 = 0.9989388...

である(複数の別解がある).
これは (7/6)9 が 4 に非常に近い値を取る(= 4.004249...)ことによる.

その2: 逆に最も 1 から遠い答は

(8/1)10 / (2/7)9 = 84627647627264.05...

である. 分子をなるべく大きく, 分母をなるべく小さくすることで得られる.

i = [1,2,3,4,5,6,7,8,9,10]
h = {}
for a in i:
for b in i:
for c in i:
for d in i:
for e in i:
for f in i:
if len(set([a,b,c,d,e,f])) == 6:
k = '({}/{})**{} / ({}/{})**{}'.format(a,b,c,d,e,f)
v = (a/b)**c / (d/e)**f
h[k] = v
s = sorted(h.items(), key=lambda x:x[1])
for x in s:
print('{} = {}'.format(x[0],x[1]))
(2/7)**9 / (8/1)**10 = 1.1816469298596399e-14
(1/8)**10 / (7/2)**9 = 1.1816469298596405e-14
(1/9)**10 / (7/2)**8 = 1.2735926697953054e-14
(2/7)**8 / (9/1)**10 = 1.2735926697953054e-14
(1/7)**10 / (8/2)**9 = 1.3504536341253028e-14
...(151190 行省略) ...
(8/2)**9 / (1/7)**10 = 74049191673856.03
(7/2)**8 / (1/9)**10 = 78518039850270.36
(9/1)**10 / (2/7)**8 = 78518039850270.36
(7/2)**9 / (1/8)**10 = 84627647627264.0
(8/1)**10 / (2/7)**9 = 84627647627264.05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment