{"id":4846,"date":"2019-03-20T06:00:15","date_gmt":"2019-03-20T04:00:15","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=4846"},"modified":"2022-03-26T12:09:47","modified_gmt":"2022-03-26T10:09:47","slug":"siguiente-mayor","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/siguiente-mayor\/","title":{"rendered":"Siguiente mayor"},"content":{"rendered":"<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\"> \n   siguienteMayor :: Ord a => [a] -> [Maybe a]\n<\/pre>\n<p>tal que (siguienteMayos xs) es la lista obtenida sustiyendo cada elemento de xs por el primer elemento de xs a la derechha de x que sea mayor que x, si existe y Nothing en caso contrario. Por ejemplo,<\/p>\n<pre lang=\"text\"> \n   \u03bb> siguienteMayor [4,5,2,3,9]\n   [Just 5,Just 9,Just 3,Just 9,Nothing]\n   \u03bb> siguienteMayor [9,5,2,3,4]\n   [Nothing,Nothing,Just 3,Just 4,Nothing]\n   \u03bb> siguienteMayor [9,5,2,2,4]\n   [Nothing,Nothing,Just 4,Just 4,Nothing]\n   \u03bb> siguienteMayor \"betis\"\n   [Just 'e',Just 't',Nothing,Just 's',Nothing]\n   \u03bb> siguienteMayor \"sevilla\"\n   [Just 'v',Just 'v',Nothing,Just 'l',Nothing,Nothing,Nothing]\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\nimport Data.Maybe (listToMaybe)\n\n-- 1\u00aa soluci\u00f3n\nsiguienteMayor :: Ord a => [a] -> [Maybe a]\nsiguienteMayor [] = []\nsiguienteMayor (x:xs)\n  | null ys   = Nothing : siguienteMayor xs\n  | otherwise = Just (head ys) : siguienteMayor xs\n  where ys = [y | y <- xs, y > x]\n\n-- 2\u00aa soluci\u00f3n\nsiguienteMayor2 :: Ord a => [a] -> [Maybe a]\nsiguienteMayor2 []     = []\nsiguienteMayor2 (x:xs) = listToMaybe [y | y <- xs, y > x] : siguienteMayor2 xs\n\n-- 3\u00aa soluci\u00f3n\nsiguienteMayor3 :: Ord a => [a] -> [Maybe a]\nsiguienteMayor3 []     = []\nsiguienteMayor3 (x:xs) = listToMaybe (dropWhile (<=x) xs) : siguienteMayor3 xs\n<\/pre>\n<h4>Pensamiento<\/h4>\n<blockquote><p>\nSi vivir es bueno<br \/>\nes mejor so\u00f1ar,<br \/>\ny mejor que todo,<br \/>\nmadre, despertar.<\/p>\n<p>Antonio Machado\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Definir la funci\u00f3n siguienteMayor :: Ord a => [a] -> [Maybe a] tal que (siguienteMayos xs) es la lista obtenida sustiyendo cada elemento de xs por el primer elemento de xs a la derechha de x que sea mayor que x, si existe y Nothing en caso contrario. Por ejemplo, \u03bb> siguienteMayor [4,5,2,3,9] [Just 5,Just&#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":[8,500,59,71,246,141,11,6],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4846"}],"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=4846"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4846\/revisions"}],"predecessor-version":[{"id":4888,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/4846\/revisions\/4888"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=4846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=4846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=4846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}