You are viewing a single comment's thread. Return to all comments →
Haskell
import Control.Applicative import Control.Monad import System.IO import Data.Set (Set) import qualified Data.Set as Set palindrome :: [Int] palindrome = [x*y | y <- [100 .. 999], x <- [y .. 999], (x*y) <= 1000000, (x*y) == read (reverse (show (x*y)))] cap :: [Int] -> Int -> [Int] cap xs n = filter (<n) xs findMax :: [Int] -> Int findMax [x] = x findMax (x:y:xs) | x > y = findMax (x:xs) | otherwise = findMax (y:xs) 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 palList = cap palindrome n putStrLn(show (findMax palList))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #4: Largest palindrome product
You are viewing a single comment's thread. Return to all comments →
Haskell