続・0〜9の数字を使って、掛け算して、Go!解けた。
数値のリストを文字列に変換する方法が分かったので、早速試してみた。
import List main = putStrLn $ unlines $ map format $ filter test $ perm [0,1,2,3,5,6,7,8,9] perm [] = [[]] perm xs = concat [map (x:) $ perm (delete x xs) | x <- xs] test [a,b,c,d,e,f,g,h,i] = if (400 + a*10 + b) * (c*10 + d) == (e*10000 + f*1000 + g*100 + h*10 + i) then True else False format [a,b,c,d,e,f,g,h,i] = nlistToString [4,a,b] ++ " x " ++ nlistToString[c,d ] ++ " = " ++ nlistToString [e,f,g,h,i] nlistToString nl = concat $ map show nl
結果はこう。
402 x 39 = 15678 483 x 12 = 05796 495 x 36 = 17820
改行が余分に出るのはナゼだろう、、
まあでも、最初のバージョンよりは見やすくなったのは確か。