{"id":1870,"date":"2015-12-17T06:00:36","date_gmt":"2015-12-17T04:00:36","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=1870"},"modified":"2015-12-24T08:56:52","modified_gmt":"2015-12-24T06:56:52","slug":"suma-de-elementos-en-posiciones-dadas","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/suma-de-elementos-en-posiciones-dadas\/","title":{"rendered":"Suma de elementos en posiciones dadas"},"content":{"rendered":"<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   sumaEnPosicion :: [Int] -> [Int] -> Int\n<\/pre>\n<p>tal que (sumaEnPosicion xs ys) es la suma de todos los elementos de xs cuyas posiciones se indican en ys. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   sumaEnPosicion [1,2,3] [0,2]  ==  4\n   sumaEnPosicion [4,6,2] [1,3]  ==  6\n   sumaEnPosicion [3,5,1] [0,1]  ==  8\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa soluci\u00f3n\nsumaEnPosicion1 :: [Int] -> [Int] -> Int\nsumaEnPosicion1 xs ys = sum [xs !! y | y <- ys, 0 <= y, y < n]\n    where n = length xs\n\n-- 2\u00aa soluci\u00f3n\nsumaEnPosicion2 :: [Int] -> [Int] -> Int\nsumaEnPosicion2 xs ys = aux xs [y | y <- ys, 0 <= y, y < n] 0\n    where n = length xs\n          aux _  []     r = r\n          aux xs (y:ys) r = aux xs ys (r + xs!!y)\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Definir la funci\u00f3n sumaEnPosicion :: [Int] -> [Int] -> Int tal que (sumaEnPosicion xs ys) es la suma de todos los elementos de xs cuyas posiciones se indican en ys. Por ejemplo, sumaEnPosicion [1,2,3] [0,2] == 4 sumaEnPosicion [4,6,2] [1,3] == 6 sumaEnPosicion [3,5,1] [0,1] == 8 Soluciones &#8212; 1\u00aa soluci\u00f3n sumaEnPosicion1 :: [Int] ->&#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,28,6,40],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1870"}],"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=1870"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1870\/revisions"}],"predecessor-version":[{"id":1908,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1870\/revisions\/1908"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=1870"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=1870"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=1870"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}