読者です 読者をやめる 読者になる 読者になる

send more money

プログラミング
import Control.Monad
import Control.Applicative

digit :: MonadPlus m => m Int
digit = msum $ map return [0..9]

exps :: Num a => [a]
exps = map (10 ^) [0..]

number :: Num a => [a] -> a
number = sum . zipWith (*) exps . reverse

uniqueDigits 0 = return []
uniqueDigits n = do
  xs <- uniqueDigits (n - 1)
  x <- digit
  guard $ x `notElem` xs
  return (x:xs)

sendmoremoney = do
  [s,e,n,d,m,o,r,y] <- uniqueDigits 8
  guard $ s /= 0
  guard $ m /= 0
  guard $ number [s, e, n, d] + number [m, o, r, e] == number [m, o, n, e, y]
  return [s, e, n, d, m, o, r, y]

main = print $ (sendmoremoney :: [[Int]])