
Hi Marc
Une tres jolie petite probleme !
Voila une solution brute-force dans une ligne de code.
Esseyer !
Hugs> last [ a*b | a <- [1..100], b<- [1..100], (show $ a*b) == reverse ( show $ a*b) ]
9009
Hugs> last [ a*b | a <- [1..1000], b<- [1..1000], (show $ a*b) == reverse ( show $ a*b) ]
90909
Hugs> last [ a*b | a <- [1..1000], b<- [1..1000], (show $ a*b) == reverse ( show $ a*b) ]
Hugs> last [ (a,b,a*b) | a <- [1..1000], b<- [1..1000], (show $ a*b) == reverse ( show $ a*b) ]
(999,91,90909)
Si vous aves des question, n'hesite pas !
:)
Dan
--- On Sun, 1/31/10, Marc Chantreux
From: Marc Chantreux
Subject: [Haskell-fr] euler 4: vos commentaires ? To: haskell-fr@haskell.org Date: Sunday, January 31, 2010, 11:41 PM Bonjour a tous, toujours dans mes petites tentatives épisodiques, j'ai résolu ce WE le 4eme pb du euler project. J'imagine que ma résolution sera d'une naiveté touchante pour les plus experimentés d'entre vous et c'est bien le but de ce présent message: pourriez-vous, svp, émettre toutes les critiques qui vous viennent a l'esprit?
cordialement, marc
{- - http://projecteuler.net/index.php?section=problems&id=4 - A palindromic number reads the same both ways. - The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. - - Find the largest palindrome made from the product of two 3-digit numbers. - -}
products max = let g = reverse [1..max] in [ (x,y, show $ x * y ) | x <- g, y <- g ]
is_palindrome x = x == reverse x
palindromes = filter ( \(_,_,x) -> is_palindrome x )
bigger_palindrome x = take 1 $ palindromes x
main = mapM (putStrLn . show) $ map (bigger_palindrome . products ) [99,999,9999] _______________________________________________ Haskell-fr mailing list Haskell-fr@haskell.org http://www.haskell.org/mailman/listinfo/haskell-fr