{"id":5200,"date":"2019-12-02T05:30:12","date_gmt":"2019-12-02T03:30:12","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=5200"},"modified":"2019-12-11T08:37:38","modified_gmt":"2019-12-11T06:37:38","slug":"multiplos-palindromos","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/multiplos-palindromos\/","title":{"rendered":"M\u00faltiplos pal\u00edndromos"},"content":{"rendered":"<p>Los n\u00fameros 545, 5995 y 15151 son los tres menores pal\u00edndromos (capic\u00faas) que son divisibles por 109.<\/p>\n<p>Definir las funciones<\/p>\n<pre lang=\"text\">\n   multiplosPalindromos :: Integer -> [Integer]\n   multiplosPalindromosMenores :: Integer -> Integer -> [Integer]\n<\/pre>\n<p>tales que<\/p>\n<ul>\n<li>(multiplosPalindromos n) es la lista de los pal\u00edndromos divisibles por n. Por ejemplo, <\/li>\n<\/ul>\n<pre lang=\"text\">\n     take 5 (multiplosPalindromos 109) == [545,5995,15151,64746,74447]\n<\/pre>\n<ul>\n<li>(multiplosPalindromosMenores x n) es la lista de los pal\u00edndromos divisibles por n, menores que x. Por ejemplo,<\/li>\n<\/ul>\n<pre lang=\"text\">\n     \u03bb> multiplosPalindromosMenores (10^5) 109\n     [545,5995,15151,64746,74447,79897,84148,89598,99299]\n<\/pre>\n<p><strong>Nota<\/strong>: Este ejercicio est\u00e1 basado en el <a href=\"https:\/\/projecteuler.net\/problem=655\">problema 655<\/a> del <a href=\"https:\/\/projecteuler.net\">Proyecto Euler<\/a>.<\/p>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa definici\u00f3n de multiplosPalindromos\n-- =====================================\n\nmultiplosPalindromos :: Integer -> [Integer]\nmultiplosPalindromos n =\n  [x | x <- multiplos n\n     , esPalindromo x]\n\n-- (esPalindromo n) se verifica si n es pal\u00edndromo. Por ejemplo, \n--    esPalindromo 32523  ==  True\n--    esPalindromo 32533  ==  False\nesPalindromo :: Integer -> Bool\nesPalindromo n = reverse xs == xs\n  where xs = show n\n\n-- (multiplos n) es la lista de los m\u00faltiplos de n. Por ejemplo, \n--    take 12 (multiplos 5)  ==  [5,10,15,20,25,30,35,40,45,50,55,60]\nmultiplos :: Integer -> [Integer]\nmultiplos n = [n,2*n..]\n\n-- 2\u00aa definici\u00f3n de multiplosPalindromos\n-- =====================================\n\nmultiplosPalindromos2 :: Integer -> [Integer]\nmultiplosPalindromos2 = filter esPalindromo . multiplos \n\n-- 1\u00aa definici\u00f3n de multiplosPalindromosMenores\n-- ============================================\n\nmultiplosPalindromosMenores :: Integer -> Integer -> [Integer]\nmultiplosPalindromosMenores x n =\n  takeWhile (<x) (multiplosPalindromos n)\n\n-- 2\u00aa definici\u00f3n de multiplosPalindromosMenores\n-- ============================================\n\nmultiplosPalindromosMenores2 :: Integer -> Integer -> [Integer]\nmultiplosPalindromosMenores2 x =\n  takeWhile (<x) . multiplosPalindromos\n<\/pre>\n<h4>Pensamiento<\/h4>\n<blockquote><p>\nEsta luz de Sevilla... Es el palacio<br \/>\ndonde nac\u00ed, con su rumor de fuente.<\/p>\n<p>Antonio Machado\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Los n\u00fameros 545, 5995 y 15151 son los tres menores pal\u00edndromos (capic\u00faas) que son divisibles por 109. Definir las funciones multiplosPalindromos :: Integer -> [Integer] multiplosPalindromosMenores :: Integer -> Integer -> [Integer] tales que (multiplosPalindromos n) es la lista de los pal\u00edndromos divisibles por n. Por ejemplo, take 5 (multiplosPalindromos 109) == [545,5995,15151,64746,74447] (multiplosPalindromosMenores x&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[4],"tags":[8,481,38,11,32,33,34],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5200"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/comments?post=5200"}],"version-history":[{"count":4,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5200\/revisions"}],"predecessor-version":[{"id":5244,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5200\/revisions\/5244"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=5200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=5200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=5200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}