{"id":3051,"date":"2017-03-06T06:00:04","date_gmt":"2017-03-06T04:00:04","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=3051"},"modified":"2017-03-13T10:58:56","modified_gmt":"2017-03-13T08:58:56","slug":"numeros-binarios-invertidos","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/numeros-binarios-invertidos\/","title":{"rendered":"N\u00fameros binarios invertidos"},"content":{"rendered":"<p>La representaci\u00f3n binaria de 13 es 1101, que al invertirlo da 1011 cuya representaci\u00f3n decimal es el n\u00famero 11.<\/p>\n<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   transformado :: Integer -> Integer\n<\/pre>\n<p>tal que (transformado x) es la representaci\u00f3n decimal del n\u00famero obtenido invirtiendo la representaci\u00f3n binaria de x. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   transformado 13  ==  11\n   transformado 47  ==  61\n<\/pre>\n<p><strong>Nota<\/strong>: El ejercicio est\u00e1 basado en el problema <a href=\"http:\/\/bit.ly\/2n3ldsD\">Reversed Binary Numbers<\/a> de Kattis.<\/p>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\ntransformado :: Integer -> Integer \ntransformado = bin2int . reverse . int2bin\n\n-- (int2bin x) es la representaci\u00f3n binaria de x. Por ejemplo,\n--    int2bin 13  ==  [1,0,1,1]\nint2bin :: Integer -> [Integer]\nint2bin n | n < 2     = [n]\n          | otherwise = n `mod` 2 : int2bin (n `div` 2)\n\n-- (bin2int x) es la representaci\u00f3n decimal del n\u00famero binario x. Por\n-- ejemplo, \n--    bin2int [1,0,1,1]           ==  13\n--    bin2int (reverse [1,0,1,1]) ==  11\nbin2int :: [Integer] -> Integer\nbin2int =  foldr (\\x y -> x + 2*y) 0\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>La representaci\u00f3n binaria de 13 es 1101, que al invertirlo da 1011 cuya representaci\u00f3n decimal es el n\u00famero 11. Definir la funci\u00f3n transformado :: Integer -> Integer tal que (transformado x) es la representaci\u00f3n decimal del n\u00famero obtenido invirtiendo la representaci\u00f3n binaria de x. Por ejemplo, transformado 13 == 11 transformado 47 == 61 Nota:&#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":[30,94,89,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\/3051"}],"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=3051"}],"version-history":[{"count":3,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3051\/revisions"}],"predecessor-version":[{"id":3086,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/3051\/revisions\/3086"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=3051"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=3051"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=3051"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}