The product 7254 is unusual, as the identity, 39 x 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
import Data.List pdct n = [z|(x,y)<-map(splitAt n)digit,let z =read x*read y,sort (x++y++show z)=="123456789"] where digit = perm "123456789" 5 perm _ = [] perm xs (n+1) = [a:b|a<-xs,b<-perm (delete a xs) n] p032 = sum.nub $ pdct 1 ++ pdct 2
作成者 Toru Mano
最終更新時刻 2022-08-21 (e8774a4)