{"id":1271,"date":"2015-04-02T06:00:53","date_gmt":"2015-04-02T04:00:53","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=1271"},"modified":"2015-05-01T08:41:15","modified_gmt":"2015-05-01T06:41:15","slug":"ampliacion-de-una-matriz-sumando-sus-filas","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/ampliacion-de-una-matriz-sumando-sus-filas\/","title":{"rendered":"Ampliaci\u00f3n de una matriz sumando sus filas"},"content":{"rendered":"<p>Representamos las matrices mediante el tipo de dato<\/p>\n<pre lang=\"text\">\n   type Matriz a = Array (Int,Int) a\n<\/pre>\n<p>Por ejemplo,<\/p>\n<pre lang=\"text\">\n   ejM :: Matriz Int\n   ejM = listArray ((1,1),(2,4)) [1,2,3,0,4,5,6,7]\n<\/pre>\n<p>representa la matriz<\/p>\n<pre lang=\"text\">\n   |1 2 3 0|\n   |4 5 6 7|\n<\/pre>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   ampliada :: Num a => Matriz a -> Matriz a\n<\/pre>\n<p>tal que (ampliada p) es la matriz obtenida al a\u00f1adir una nueva fila  a p cuyo elemento i-\u00e9simo es la suma de la columna i-\u00e9sima de p.  Por ejemplo,<\/p>\n<pre lang=\"text\">\n   |1 2 3 0|        |1 2 3 0|\n   |4 5 6 7| ==>    |4 5 6 7| \n                    |5 7 9 7|\n<\/pre>\n<p>En Haskell,<\/p>\n<pre lang=\"text\">\n   ghci> ampliada ejM\n   array ((1,1),(3,4)) [((1,1),1),((1,2),2),((1,3),3),((1,4),0),\n                        ((2,1),4),((2,2),5),((2,3),6),((2,4),7),\n                        ((3,1),5),((3,2),7),((3,3),9),((3,4),7)]\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\nimport Data.Array\n\ntype Matriz a = Array (Int,Int) a\n\nejM :: Matriz Int\nejM = listArray ((1,1),(2,4)) [1,2,3,0,4,5,6,7]\n\nampliada :: Num a => Matriz a -> Matriz a\nampliada p = \n    array ((1,1),(m+1,n)) [((i,j),f i j) | i <- [1..m+1], j <- [1..n]]\n    where (_,(m,n)) = bounds p\n          f i j | i <= m    = p!(i,j)\n                | otherwise = sum [p!(i,j) | i <- [1..m]] \n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Representamos las matrices mediante el tipo de dato type Matriz a = Array (Int,Int) a Por ejemplo, ejM :: Matriz Int ejM = listArray ((1,1),(2,4)) [1,2,3,0,4,5,6,7] representa la matriz |1 2 3 0| |4 5 6 7| Definir la funci\u00f3n ampliada :: Num a => Matriz a -> Matriz a tal que (ampliada p) es&#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":[250,43,42,40],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1271"}],"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=1271"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1271\/revisions"}],"predecessor-version":[{"id":1311,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/1271\/revisions\/1311"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=1271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=1271"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=1271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}