You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO import Data.Char(digitToInt) slice :: Int -> Int -> [a] -> [a] slice start end xs = take (end - start) (drop start xs) strMult :: [Char] -> Int strMult [chr] = digitToInt chr strMult (chr:str) = (digitToInt chr) * (strMult str) subMult :: [Char] -> Int -> Int -> [Int] subMult num start end | end == (length num) - 1 = [strMult (slice start end num)] | otherwise = (strMult (slice start end num)):(subMult num (start+1) (end+1)) main :: IO () main = do t_temp <- getLine let t = read t_temp :: Int forM_ [1..t] $ \a0 -> do n_temp <- getLine let n_t = words n_temp let n = read $ n_t!!0 :: Int let k = read $ n_t!!1 :: Int ' num <- getLine let multList = subMult num 0 k print (maximum multList)
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →
Haskell