Problem 39
コンテンツ
If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120.
{20,48,52}, {24,45,51}, {30,40,50}
For which value of p 1000, is the number of solutions maximised?
これはピタゴラス数の生成だ。
import Data.List import Data.Ord pythagoras l = [2*k*m*(n+m)|n<-[1..l],m<-[(n+1)..(l`div`(n+1))], k<-[1..(l`div`(2*m*(n+1)))],even m || even n, gcd m n == 1 ,m>n,2*k*m*(n+m) < l] count xs@(x:_)=(x,length xs) p039 =fst.maximumBy(comparing snd).map count.group.sort.pythagoras
作成者 Toru Mano
最終更新時刻 2023-01-01 (c70d5a1)