Hi,
I posted this already in "Problems archive" but realised this would maybe be a more appropiate place.
I've written a solution to the problem PALIN and I think it's correct.
But when I submit it, it gives a time limit. Can anyone tell me what's wrong?
Cheers,
fonsvdlaan
module Main where
import Data.List
main :: IO ()
main = do
numberofcasesstring <- getLine
let numberofcases = read numberofcasesstring
listofcasesstring <- getContents
let listofcases = map read (words listofcasesstring)
let listofanswers = getPalindromes numberofcases listofcases
let listofanswersstring = intercalate "\n" (map show listofanswers)
putStr listofanswersstring
getPalindromes :: Int -> [Int] -> [Int]
getPalindromes 0 _ = []
getPalindromes n (x:xs) = (palindrome x) : (getPalindromes (n-1) xs)
palindrome :: Int -> Int
palindrome x | isPalindrome x = x
| otherwise = palindrome (x+1)
isPalindrome :: Int -> Bool
isPalindrome x = (show x) == reverse (show x)
created
last reply
- 3
replies
- 1.2k
views
- 2
users