{"id":319,"date":"2014-06-18T07:00:52","date_gmt":"2014-06-18T05:00:52","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=319"},"modified":"2014-11-29T12:32:45","modified_gmt":"2014-11-29T10:32:45","slug":"seleccion-hasta-el-primero-que-falla-inclusive","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/seleccion-hasta-el-primero-que-falla-inclusive\/","title":{"rendered":"Selecci\u00f3n hasta el primero que falla inclusive"},"content":{"rendered":"<h4>Enunciado<\/h4>\n<pre lang=\"text\">\n-- Definir la funci\u00f3n\n--    seleccionConFallo :: (a -> Bool) -> [a] -> [a]\n-- tal que (seleccionConFallo p xs) es la lista de los elementos de xs\n-- que cumplen el predicado p hasta el primero que no lo cumple\n-- inclusive. Por ejemplo,\n--    seleccionConFallo (<5) [3,2,5,7,1,0]  ==  [3,2,5]\n--    seleccionConFallo odd [1..4]          ==  [1,2]\n--    seleccionConFallo odd [1,3,5]         ==  [1,3,5]\n--    seleccionConFallo (<5) [10..20]       ==  [10]\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa soluci\u00f3n (por recursi\u00f3n):\nseleccionConFallo1 :: (a -> Bool) -> [a] -> [a]\nseleccionConFallo1 p []                 = []\nseleccionConFallo1 p (x:xs) | p x       = x : seleccionConFallo1 p xs\n                            | otherwise = [x]\n\n-- 2\u00aa soluci\u00f3n (con span):\nseleccionConFallo2 :: (a -> Bool) -> [a] -> [a]\nseleccionConFallo2 p xs = ys ++ take 1 zs\n    where (ys,zs) = span p xs\n<\/pre>\n<h4>Referencia<\/h4>\n<p>El ejercicio est\u00e1 basado en el <a href=\"http:\/\/bit.ly\/SZi79R\">problema del 29 de abril<\/a> de <a href=\"https:\/\/twitter.com\/1HaskellADay\">1HaskellADay<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enunciado &#8212; Definir la funci\u00f3n &#8212; seleccionConFallo :: (a -> Bool) -> [a] -> [a] &#8212; tal que (seleccionConFallo p xs) es la lista de los elementos de xs &#8212; que cumplen el predicado p hasta el primero que no lo cumple &#8212; inclusive. Por ejemplo, &#8212; seleccionConFallo ( [a] -> [a] seleccionConFallo1 p []&#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":[11,6,60,47],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/319"}],"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=319"}],"version-history":[{"count":6,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/319\/revisions"}],"predecessor-version":[{"id":687,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/319\/revisions\/687"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}