{"id":5116,"date":"2019-11-15T06:00:57","date_gmt":"2019-11-15T04:00:57","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=5116"},"modified":"2019-11-22T08:47:17","modified_gmt":"2019-11-22T06:47:17","slug":"mayor-prefijo-comun","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/mayor-prefijo-comun\/","title":{"rendered":"Mayor prefijo com\u00fan"},"content":{"rendered":"<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   mayorPrefijoComun :: Eq a => [a] -> [a] -> [a]\n<\/pre>\n<p>tal que (mayorPrefijoComun xs ys) calcula el mayor prefijo com\u00fan a xs e ys. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   mayorPrefijoComun \"masa\" \"madre\"       == \"ma\"\n   mayorPrefijoComun \"masa\" \"padre\"       == \"\"\n   mayorPrefijoComun \"hola\" \"hielo\"       == \"h\"\n   mayorPrefijoComun \"helado\" \"heladeria\" == \"helad\"\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa soluci\u00f3n\nmayorPrefijoComun :: Eq a => [a] -> [a] -> [a]\nmayorPrefijoComun _  [] = []\nmayorPrefijoComun [] _  = []\nmayorPrefijoComun (x:xs) (y:ys)\n  | x == y    = x : mayorPrefijoComun xs ys\n  | otherwise = []\n\n-- 2\u00aa soluci\u00f3n\nmayorPrefijoComun2 :: Eq a => [a] -> [a] -> [a]\nmayorPrefijoComun2 xs ys =\n  [x | (x,_) <- takeWhile iguales (zip xs ys)]\n  where iguales (x,y) = x == y\n<\/pre>\n<h4>Pensamiento<\/h4>\n<blockquote><p>\nLos ojos por que suspiras,<br \/>\ns\u00e1belo bien,<br \/>\nlos ojos en que te miras<br \/>\nson ojos porque te ven.<\/p>\n<p>Antonio Machado\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Definir la funci\u00f3n mayorPrefijoComun :: Eq a => [a] -> [a] -> [a] tal que (mayorPrefijoComun xs ys) calcula el mayor prefijo com\u00fan a xs e ys. Por ejemplo, mayorPrefijoComun \u00abmasa\u00bb \u00abmadre\u00bb == \u00abma\u00bb mayorPrefijoComun \u00abmasa\u00bb \u00abpadre\u00bb == \u00ab\u00bb mayorPrefijoComun \u00abhola\u00bb \u00abhielo\u00bb == \u00abh\u00bb mayorPrefijoComun \u00abhelado\u00bb \u00abheladeria\u00bb == \u00abhelad\u00bb Soluciones &#8212; 1\u00aa soluci\u00f3n mayorPrefijoComun ::&#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":[5],"tags":[6],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5116"}],"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=5116"}],"version-history":[{"count":4,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5116\/revisions"}],"predecessor-version":[{"id":5151,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/5116\/revisions\/5151"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=5116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=5116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=5116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}