{"id":7328,"date":"2022-09-09T06:00:39","date_gmt":"2022-09-09T04:00:39","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=7328"},"modified":"2022-12-14T14:34:57","modified_gmt":"2022-12-14T12:34:57","slug":"numero-de-raices-de-la-ecuacion-de-segundo-grado","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/numero-de-raices-de-la-ecuacion-de-segundo-grado\/","title":{"rendered":"N\u00famero de ra\u00edces de la ecuaci\u00f3n de segundo grado"},"content":{"rendered":"<p>Definir la funci\u00f3n<\/p>\n<pre lang=\"text\">\n   numeroDeRaices :: (Num t, Ord t) => t -> t -> t -> Int\n<\/pre>\n<p>tal que <code>(numeroDeRaices a b c)<\/code> es el n\u00famero de ra\u00edces reales de la ecuaci\u00f3n <img decoding=\"async\" src=\"https:\/\/s0.wp.com\/latex.php?latex=ax%5E2+%2B+bx+%2B+c+%3D+0&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\"ax^2 + bx + c = 0\" class=\"latex\" \/>. Por ejemplo,<\/p>\n<pre lang=\"text\">\n   numeroDeRaices 2 0 3    ==  0\n   numeroDeRaices 4 4 1    ==  1\n   numeroDeRaices 5 23 12  ==  2\n<\/pre>\n<p><b>Soluciones<\/b><\/p>\n<p>A continuaci\u00f3n se muestran las <a href=\"#haskell\">soluciones en Haskell<\/a> y las <a href=\"#python\">soluciones en Python<\/a>.<\/p>\n<p><a name=\"haskell\"><\/a><br \/>\n<b>Soluciones en Haskell<\/b><\/p>\n<pre lang=\"haskell\">\nnumeroDeRaices :: (Num t, Ord t) => t -> t -> t -> Int\nnumeroDeRaices a b c | d < 0     = 0\n                     | d == 0    = 1\n                     | otherwise = 2\n  where d = b^2-4*a*c\n<\/pre>\n<p>El c\u00f3digo se encuentra en <a href=\"https:\/\/github.com\/jaalonso\/Exercitium\/blob\/main\/src\/Numero_de_raices_de_la_ecuacion_de_segundo_grado.hs\">GitHub<\/a>.<\/p>\n<p><a name=\"python\"><\/a><br \/>\n<b>Soluciones en Python<\/b><\/p>\n<pre lang=\"python\">\ndef numeroDeRaices(a: float, b: float, c: float) -> float:\n    d = b ** 2 - 4 * a * c\n    if d < 0:\n        return 0\n    if d == 0:\n        return 1\n    return 2\n<\/pre>\n<p>El c\u00f3digo se encuentra en <a href=\"https:\/\/github.com\/jaalonso\/Exercitium-Python\/blob\/main\/src\/numero_de_raices_de_la_ecuacion_de_segundo_grado.\u1ef3\">GitHub<\/a>.<\/p>\n<p><b>Comentarios<\/b><\/p>\n<ul>\n<li>En Haskell se usa un entorno local con <code>where d = b^2-4*a*c<\/code> y en Python se usa la asignaci\u00f3n <code>d = b ** 2 - 4 * a * c<\/code>.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Definir la funci\u00f3n numeroDeRaices :: (Num t, Ord t) => t -> t -> t -> Int tal que (numeroDeRaices a b c) es el n\u00famero de ra\u00edces reales de la ecuaci\u00f3n . Por ejemplo, numeroDeRaices 2 0 3 == 0 numeroDeRaices 4 4 1 == 1 numeroDeRaices 5 23 12 == 2 Soluciones A&#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":[581],"tags":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/7328"}],"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=7328"}],"version-history":[{"count":2,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/7328\/revisions"}],"predecessor-version":[{"id":7695,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/7328\/revisions\/7695"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=7328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=7328"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=7328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}