Project Euler #16: Power digit sum

  • + 0 comments

    Haskell

    import Control.Applicative
    import Control.Monad
    import System.IO
    import Data.Char
    
    main :: IO ()
    main = do
        t_temp <- getLine
        let t = read t_temp :: Int
        forM_ [1..t] $ \a0  -> do
            n_temp <- getLine
            let n = read n_temp :: Int
            let num = 2^n
            let num_string = show num
            let digits = map (\x -> digitToInt x) num_string
            print(sum digits)