Erik the outgolferのおかげで-1バイト(クイックを活用してください¥
)
SHð;_P
ṗ3Ç⁼¥Ðf²Ḣ
ヘロンの式のブルートフォースアプリケーション。
オンラインでお試しください!(114テストの場合は60秒のタイムアウトに達します。ローカルで3分30秒かかります-114 3 = 1,481,544トリプルをチェックします)
どうやって?
真のゴルフソリューション- との間の3つの整数のすべてのタプルをa
見つけるエリアを指定すると(繰り返される三角形とエリアのないものでも)、そのエリアと目的のエリアのフィルターを取得します(すぐに停止することさえありません) 1つが見つかった場合、それらをすべて処理し、その後最初の結果をポップします)。存在しない場合は降伏します。1
a
0
SHð;_P - Link 1, get the square of the area of a triangle: list of sides
S - sum the sides (get the perimeter)
H - halve
ð - dyadic chain separation (call that p)
_ - subtraction (vectorises) = [p-side1, p-side2, p-side3]
; - concatenate = [p, p-side1, p-side2, p-side3]
P - product = p*(p-side1)*(p-side2)*(p-side3)
= the square of Heron's formula = area squared
ṗ3Ç⁼¥Ðf²Ḣ - Main link: number a (area)
ṗ3 - third Cartesian power (all triples of [1,area] : [[1,1,1],[1,1,2],[1,2,1],[1,2,2],[2,1,1],[2,1,2],[2,2,1],[2,2,2], ... ,[a,a,a]]
² - square a
Ðf - filter keep if:
¥ - last two links as a dyad:
Ç - call last link (1) as a monad f(list of sides)
⁼ - left (that result) equals right (square of a)?
Ḣ - head - get the first one (an empty list yields 0, perfect for the falsey case)