{"id":16433,"date":"2022-08-18T13:31:23","date_gmt":"2022-08-18T12:31:23","guid":{"rendered":"https:\/\/complex-systems-ai.com\/?page_id=16433"},"modified":"2024-09-27T13:06:05","modified_gmt":"2024-09-27T12:06:05","slug":"ex-structures-algorithmiques","status":"publish","type":"page","link":"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/","title":{"rendered":"12 Corrected exercises on algorithmic structures"},"content":{"rendered":"<div data-elementor-type=\"wp-page\" data-elementor-id=\"16433\" class=\"elementor elementor-16433\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-13ed037 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"13ed037\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-92c026e\" data-id=\"92c026e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3a8bb2b elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"3a8bb2b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Algorithmic<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-46fcce7\" data-id=\"46fcce7\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a4385f1 elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"a4385f1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/complex-systems-ai.com\/en\/\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Home page<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-c1af0c5\" data-id=\"c1af0c5\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-414ed68 elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"414ed68\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/en.wikipedia.org\/wiki\/Algorithm\" target=\"_blank\" rel=\"noopener\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Wiki<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d7e9141 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d7e9141\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a9cb248\" data-id=\"a9cb248\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0ad9720 elementor-widget elementor-widget-heading\" data-id=\"0ad9720\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercices-corriges-sur-les-structures-algorithmiques\" >Corrected exercises on algorithmic structures<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-1\" >Exercise 1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-2\" >Exercise 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-3\" >Exercise 3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-4\" >Exercise 4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-5\" >Exercise 5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-6\" >Exercise 6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-7\" >Exercise 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-8\" >Exercise 8<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-9\" >Exercise 9<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-10\" >Exercise 10<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-11\" >Exercise 11<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/corrected-exercises-on-algorithmic-structures\/#Exercice-12\" >Exercise 12<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercices-corriges-sur-les-structures-algorithmiques\"><\/span>Corrected exercises on algorithmic structures<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9df5096 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9df5096\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-cfa4f8e\" data-id=\"cfa4f8e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5c48332 elementor-widget elementor-widget-text-editor\" data-id=\"5c48332\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The following corrected exercises relate to algorithmic structures, control structures and data structures. The objective is to propose the structures most suited to the statement.<\/p><p><img decoding=\"async\" class=\"aligncenter wp-image-11096 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2020\/09\/cropped-Capture.png\" alt=\"algorithmic structures\" width=\"97\" height=\"97\" title=\"\"><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-419625b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"419625b\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1ce0137\" data-id=\"1ce0137\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c2f8657 elementor-widget elementor-widget-heading\" data-id=\"c2f8657\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-1\"><\/span>Exercise 1<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-8304189 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8304189\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0ed86f3\" data-id=\"0ed86f3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0f90126 elementor-widget elementor-widget-text-editor\" data-id=\"0f90126\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Consider the algorithms below.<br \/>(a) What will be the contents of variables a, b and possibly c after their execution?<br \/>(b) In each of the above cases, are there any unnecessary lines, and if so which ones?<\/p><p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-19860 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2.png\" alt=\"data structure\" width=\"756\" height=\"346\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2.png 756w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-300x137.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-18x8.png 18w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4abf9fa elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4abf9fa\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3b41aca\" data-id=\"3b41aca\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-cd9a9f6 elementor-widget elementor-widget-toggle\" data-id=\"cd9a9f6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2151\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2151\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2151\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2151\"><p><img decoding=\"async\" class=\"alignnone wp-image-19861 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1.png\" alt=\"data structure\" width=\"756\" height=\"566\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1.png 756w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-300x225.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-16x12.png 16w\" sizes=\"(max-width: 756px) 100vw, 756px\" \/><\/p><p>In most programming languages the last example (1.6) will not generate an error but the result will not often be &#039;3&#039;. Depending on the language, this will be the concatenation of these characters into a character string \u201cab\u201d (case of Python or JavaScript languages), or even \u201ca+b\u201d (case of the shell) or the sum of the ASCII codes corresponding to the characters &#039; 1&#039; and &#039;2&#039;, i.e. 49 + 50 = 99: the character &#039;c&#039; (case of C, C++ or Java languages). In very few languages, like PHP or perl, on the other hand, the result will be 3. Finally in other languages like pascal, which is a strongly typed language, the compilation will generate an error.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3d24dad elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3d24dad\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f88b2dd\" data-id=\"f88b2dd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bfcbf43 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"bfcbf43\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0c98737 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0c98737\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a48ab61\" data-id=\"a48ab61\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b3721a1 elementor-widget elementor-widget-heading\" data-id=\"b3721a1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-2\"><\/span>Exercise 2<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-eb9d59a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eb9d59a\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7dadf23\" data-id=\"7dadf23\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-21fc19a elementor-widget elementor-widget-text-editor\" data-id=\"21fc19a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">This multiplication technique, used in ancient Egypt, does not require knowing all the multiplication tables up to 10 but only addition and multiplication by 2.<\/span><\/p><p><span style=\"font-weight: 400;\">Here is for example the multiplication of 13 by 78. You must first write the table of powers of 2 less than or equal to 13. Then, write the table of doubles of the number 78.<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16436 size-medium\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo1-300x144.png\" alt=\"Egyptian multiplication algorithm\" width=\"300\" height=\"144\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo1-300x144.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo1-18x9.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo1.png 343w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p><p><span style=\"font-weight: 400;\">Then, you have to tick the greatest powers of 2 breaking down the number 13 (that is to say that the binary bit is equal to 1). In other words, tick the powers of 2 entering the binary conversion of the number 13 = 1101 <\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16437 size-medium\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo2-300x150.png\" alt=\"Egyptian multiplication algorithm\" width=\"300\" height=\"150\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo2-300x150.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo2-18x9.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo2.png 343w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p><p>The sum is 78+312+624=1014.<\/p><p><span style=\"font-weight: 400;\">a \u2013 Calculate the product of your choice using the Egyptian division algorithm.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">b \u2013 Is it easier to calculate the product of 78 by 13? Why ?<\/span><\/p><p><span style=\"font-weight: 400;\">c \u2013 Write the Egyptian multiplication algorithm (according to your answer of b!). Try to optimize it as best you can!<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e486f0c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e486f0c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7c573e7\" data-id=\"7c573e7\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a214a3d elementor-widget elementor-widget-toggle\" data-id=\"a214a3d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1691\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1691\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1691\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1691\"><p><span style=\"font-weight: 400;\">The easiest is to choose the smallest number for the power of 2 and therefore the largest number to be doubled. Indeed, the number of iteration is equal to the number of times that it is necessary to multiply 2 by itself to be greater than the number minus one iteration (we only keep what is strictly lower. We will therefore have a number d iteration n such that 2<\/span><span style=\"font-weight: 400;\">not<\/span><span style=\"font-weight: 400;\"> &gt; a (described number). We deduce that n&gt;log<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">(a) hence the interest that a is the smallest.<\/span><\/p><p><span style=\"font-weight: 400;\">We first recall the binary transformation of a decimal number.<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16438 size-medium\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo3-300x183.png\" alt=\"Egyptian multiplication algorithm\" width=\"300\" height=\"183\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo3-300x183.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo3-18x12.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo3.png 455w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p><p>Which gives the following algorithm:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19664 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo2.png\" alt=\"Egyptian multiplication\" width=\"533\" height=\"416\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo2.png 533w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo2-300x234.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo2-15x12.png 15w\" sizes=\"(max-width: 533px) 100vw, 533px\" \/><\/p><p>You don&#039;t have to use a temp variable to swap two values. Here is another version of the algorithm:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19675 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo3.png\" alt=\"Egyptian multiplication\" width=\"570\" height=\"357\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo3.png 570w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo3-300x188.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2023\/09\/algo3-18x12.png 18w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-036c8e7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"036c8e7\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ade5332\" data-id=\"ade5332\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d05a419 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"d05a419\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3b86eca elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3b86eca\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a84ad16\" data-id=\"a84ad16\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-51a8507 elementor-widget elementor-widget-heading\" data-id=\"51a8507\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-3\"><\/span>Exercise 3<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d5ce67e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d5ce67e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-92539a6\" data-id=\"92539a6\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-049377e elementor-widget elementor-widget-text-editor\" data-id=\"049377e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">a \u2013 Write a <a href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/\">algorithm<\/a> whose parameters are three real variables and which circularly permutes their values.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">b \u2013 Write an algorithm whose parameters are three real variables and returns the maximum value among these three values.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">c \u2013 Write an algorithm that allows the values of two variables without using an additional variable.<\/span><\/p><p><span style=\"font-weight: 400;\">d \u2013 Write an algorithm that returns true if two integers a and b have the same sign, otherwise false<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-af0fceb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"af0fceb\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-77f2cff\" data-id=\"77f2cff\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d3ab8a3 elementor-widget elementor-widget-toggle\" data-id=\"d3ab8a3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2211\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2211\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2211\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2211\"><p><span style=\"font-weight: 400;\">has -\u00a0<\/span><span style=\"font-weight: 400;\">The variables a, b and c are variables defined outside the algorithm. These values are modified even if nothing is returned. Pay attention to the order of your operations!<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16440 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo5.png\" alt=\"permutation algorithm\" width=\"427\" height=\"202\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo5.png 427w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo5-300x142.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo5-18x9.png 18w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/p><p>You can also do this without taking an additional variable. In this case we will have at the beginning (a,b,c). For example, a and b are swapped using the following operations:<\/p><p>a \u2190 a + b<\/p><p>b \u2190 a\u2013b<\/p><p>a \u2190 a\u2013b<\/p><p>We therefore have the triple of values (b,a,c). It remains to swap a and c to obtain the tripled (b,c,a).<\/p><p>Or you can also swap the three values using a series of calculations.<\/p><p>a \u2190 a + b + c;<\/p><p>c \u2190 a\u2013b\u2013c;<\/p><p>b \u2190 a\u2013b\u2013c;<\/p><p>a \u2190 a\u2013b\u2013c;<\/p><p><span style=\"font-weight: 400;\">b-\u00a0<\/span><span style=\"font-weight: 400;\">Here the algorithm must return a value, so there are inputs and outputs. There are many ways to do things, it&#039;s up to you to find variants (with several conditions in the branch for example).<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16441 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo6.png\" alt=\"max algorithm\" width=\"472\" height=\"355\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo6.png 472w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo6-300x226.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo6-16x12.png 16w\" sizes=\"(max-width: 472px) 100vw, 472px\" \/><\/p><p><span style=\"font-weight: 400;\">The idea would be to return the maximum without using additional variables.<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-17215 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im2.png\" alt=\"maximum three variable algorithm\" width=\"601\" height=\"186\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im2.png 601w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im2-300x93.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im2-18x6.png 18w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/p><p><span style=\"font-weight: 400;\">It&#039;s not very pretty there either, so we&#039;ll try to return the maximum only once without using new variables. We will permute the values to store the maximum in x (be careful, depending on the languages you can have a real impact on the values in xy and z, so use with caution!)<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-17216 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im3.png\" alt=\"maximum optimized algorithm\" width=\"332\" height=\"285\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im3.png 332w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im3-300x258.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/09\/im3-14x12.png 14w\" sizes=\"(max-width: 332px) 100vw, 332px\" \/><\/p><p><span style=\"font-weight: 400;\">vs- <span style=\"background-color: transparent; color: #000000; font-family: Arial; font-size: 11pt; white-space: pre-wrap; font-weight: var( --e-global-typography-text-font-weight );\">We just did it several times\u2026 for those who haven&#039;t followed.<\/span><\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16442 size-full\" style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-weight: var( --e-global-typography-text-font-weight ); font-size: 1.125rem;\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo7.png\" alt=\"permutation algorithm\" width=\"555\" height=\"182\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo7.png 555w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo7-300x98.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo7-18x6.png 18w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/p><p><span style=\"font-weight: 400;\">d-\u00a0<\/span><span style=\"font-weight: 400;\">We will think about a well-optimized algorithm to avoid making lots of branches. Two integers with the same sign will have their positive product! (0 is both positive and negative)<\/span><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16443 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8.png\" alt=\"identical sign algorithm\" width=\"920\" height=\"157\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8.png 920w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8-300x51.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8-768x131.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8-18x3.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo8-600x102.png 600w\" sizes=\"(max-width: 920px) 100vw, 920px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9537123 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9537123\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d554491\" data-id=\"d554491\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f51b1bb elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"f51b1bb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ed13dac elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ed13dac\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c0c1caa\" data-id=\"c0c1caa\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d37fd60 elementor-widget elementor-widget-heading\" data-id=\"d37fd60\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-4\"><\/span>Exercise 4<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-919bad1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"919bad1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c0c7973\" data-id=\"c0c7973\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e2ed7eb elementor-widget elementor-widget-text-editor\" data-id=\"e2ed7eb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><span style=\"font-weight: 400;\">Write an algorithm to solve each of the following problems: (try with different control structures FOR, WHILE, DO \u2026 WHILE, etc.).<\/span><\/p><p><span style=\"font-weight: 400;\">1- Calculation of the sum of the first N integers.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">2- Finding the minimum and the maximum in a set of N numbers.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">3- Calculation of the quotient and remainder of the division of two integers A and B without using the division operation.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">4- The calculation of the product of two integers using only the addition operation &#039;+&#039;.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">5- Determination if A is divisible by B. With A and B positive integers.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">6- Determine all the divisors of a given integer X.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">7- Determine if an integer X is prime or not.\u00a0<\/span><\/p><p><span style=\"font-weight: 400;\">8- Calculate the sum of the digits that make up a natural number N.<\/span><\/p><p>9- A reprography store charges 2 euros for the first ten photocopies, 1.50 euros for the next twenty and 1 euro beyond that.<\/p><p>10- <span style=\"font-weight: 400;\">Write an algorithm to display the season by introducing the number of the month.<\/span><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f5ffe16 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f5ffe16\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d561bb0\" data-id=\"d561bb0\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9b7512d elementor-widget elementor-widget-toggle\" data-id=\"9b7512d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1631\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1631\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1631\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1631\"><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16453 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo11.png\" alt=\"sum algorithm\" width=\"311\" height=\"263\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo11.png 311w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo11-300x254.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo11-14x12.png 14w\" sizes=\"(max-width: 311px) 100vw, 311px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16454 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12.png\" alt=\"minimum maximum algorithm\" width=\"886\" height=\"468\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12.png 886w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12-300x158.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12-768x406.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12-18x10.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo12-600x317.png 600w\" sizes=\"(max-width: 886px) 100vw, 886px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16455 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo13.png\" alt=\"algorithm rest of the quotient\" width=\"635\" height=\"303\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo13.png 635w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo13-300x143.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo13-18x9.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo13-600x286.png 600w\" sizes=\"(max-width: 635px) 100vw, 635px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16456 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo14.png\" alt=\"product algorithm\" width=\"333\" height=\"358\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo14.png 333w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo14-279x300.png 279w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo14-11x12.png 11w\" sizes=\"(max-width: 333px) 100vw, 333px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16457 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo15.png\" alt=\"divisor algorithm\" width=\"484\" height=\"501\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo15.png 484w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo15-290x300.png 290w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo15-12x12.png 12w\" sizes=\"(max-width: 484px) 100vw, 484px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16458 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16.png\" alt=\"divisor algorithm\" width=\"885\" height=\"422\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16.png 885w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16-300x143.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16-768x366.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16-18x9.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo16-600x286.png 600w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16459 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo17.png\" alt=\"prime number algorithm\" width=\"764\" height=\"592\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo17.png 764w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo17-300x232.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo17-15x12.png 15w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo17-600x465.png 600w\" sizes=\"(max-width: 764px) 100vw, 764px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16460 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18.png\" alt=\"sum of digits algorithm\" width=\"772\" height=\"274\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18.png 772w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18-300x106.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18-768x273.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18-18x6.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo18-600x213.png 600w\" sizes=\"(max-width: 772px) 100vw, 772px\" \/><\/p><p>Erratum: at the beginning R = N, otherwise the algorithm does nothing (we say that it is not correct because it does not solve the problem posed).<\/p><p>9-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16444 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo9.png\" alt=\"invoice algorithm\" width=\"522\" height=\"422\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo9.png 522w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo9-300x243.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo9-15x12.png 15w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p><p><span style=\"font-weight: 400;\">It is possible to put the branches in sequential, but that is less efficient in calculation time.<\/span><\/p><p>10-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-16445 size-full\" src=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo10.png\" alt=\"season algorithm\" width=\"416\" height=\"287\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo10.png 416w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo10-300x207.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2022\/08\/algo10-18x12.png 18w\" sizes=\"(max-width: 416px) 100vw, 416px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a90425e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a90425e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e390625\" data-id=\"e390625\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-559ac5c elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"559ac5c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ca2cd51 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ca2cd51\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-803948b\" data-id=\"803948b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4dcc7c6 elementor-widget elementor-widget-heading\" data-id=\"4dcc7c6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-5\"><\/span>Exercise 5<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-628d69b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"628d69b\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4cb605b\" data-id=\"4cb605b\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e9e015e elementor-widget elementor-widget-text-editor\" data-id=\"e9e015e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>1. Write an algorithm that asks the user for an integer, tests whether that number is positive (0) or not, and displays \u201cpositive\u201d or \u201cnegative\u201d.<\/p><p>2. Write an algorithm that asks the user for an integer, tests whether that number is strictly positive, zero, or strictly negative, and displays that result.<\/p><p>3. Write an algorithm that asks the user for a real value and displays its absolute value (without using a predefined function obviously).<\/p><p>4. Write an algorithm that asks for a real number from the user and rounds it to the nearest integer (x.5 will be rounded up to the next integer).<\/p><p>5. Write an algorithm that asks for the number of a month and displays the number of days in that month (ignoring leap years).<\/p><p>6. Write an algorithm that checks if a year is a leap year. Remember that there are leap years every 4 years, but the first year of a century is not (1800, 1900 were not leap years) except every 400 years (2000 was a leap year) .<\/p><p>7. Write an algorithm that requests a date in the form of 2 integers (day number and month number) and displays the season (ex: 02\/12; winter). It will be assumed that the first day of the season is always the 21st.<\/p><p>8. Write a program that asks for the coordinates (x, y) of the vertices A, B and C of a triangle and displays the nature of the triangle (isosceles, equilateral, rectangular or any).<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-6597948 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6597948\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f6a1aab\" data-id=\"f6a1aab\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-654b558 elementor-widget elementor-widget-toggle\" data-id=\"654b558\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1061\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1061\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1061\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1061\"><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19862 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3.png\" alt=\"control structure\" width=\"739\" height=\"715\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3.png 739w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-300x290.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-12x12.png 12w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19863 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4.png\" alt=\"control structure\" width=\"744\" height=\"546\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4.png 744w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-300x220.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-16x12.png 16w\" sizes=\"(max-width: 744px) 100vw, 744px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19864 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5.png\" alt=\"control structure\" width=\"737\" height=\"425\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5.png 737w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-300x173.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-18x10.png 18w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19865 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6.png\" alt=\"control structure\" width=\"559\" height=\"822\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6.png 559w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-204x300.png 204w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-8x12.png 8w\" sizes=\"(max-width: 559px) 100vw, 559px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-70230dc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"70230dc\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0f455c0\" data-id=\"0f455c0\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-ebb8051 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"ebb8051\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a9b3acf elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a9b3acf\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0f85853\" data-id=\"0f85853\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fe7afdf elementor-widget elementor-widget-heading\" data-id=\"fe7afdf\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-6\"><\/span>Exercise 6<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-324ae6e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"324ae6e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-bd84726\" data-id=\"bd84726\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-11633d1 elementor-widget elementor-widget-text-editor\" data-id=\"11633d1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>1. Write an algorithm that asks for a positive integer, and rejects it until the number entered does not match.<\/p><p>2. Write an algorithm that asks for 10 integers, counts the number of positive integers entered, and displays that result.<\/p><p>3. Write an algorithm that asks the user for positive integers, adds them, and stops displaying the<br \/>result as soon as a negative integer is entered.<\/p><p>4. Modify this last algorithm to display the average of the series of positive integers entered.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e0f2873 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e0f2873\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-be3bae6\" data-id=\"be3bae6\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f463710 elementor-widget elementor-widget-toggle\" data-id=\"f463710\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2561\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2561\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2561\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2561\"><p>1-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19866 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo7.png\" alt=\"control structure\" width=\"721\" height=\"203\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo7.png 721w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo7-300x84.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo7-18x5.png 18w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/p><p>2-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19867 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo8.png\" alt=\"control structure\" width=\"716\" height=\"305\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo8.png 716w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo8-300x128.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo8-18x8.png 18w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/p><p>3-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19868 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo9.png\" alt=\"control structure\" width=\"720\" height=\"239\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo9.png 720w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo9-300x100.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo9-18x6.png 18w\" sizes=\"(max-width: 720px) 100vw, 720px\" \/><\/p><p>4-<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19869 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo10.png\" alt=\"control structure\" width=\"718\" height=\"402\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo10.png 718w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo10-300x168.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo10-18x10.png 18w\" sizes=\"(max-width: 718px) 100vw, 718px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b6b81c6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b6b81c6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-afe7168\" data-id=\"afe7168\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7a3092e elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"7a3092e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d28e284 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d28e284\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4399a03\" data-id=\"4399a03\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6c07b91 elementor-widget elementor-widget-heading\" data-id=\"6c07b91\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-7\"><\/span>Exercise 7<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-dc2e2a4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"dc2e2a4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-c587c71\" data-id=\"c587c71\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-38fddd3 elementor-widget elementor-widget-text-editor\" data-id=\"38fddd3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Write an algorithm to display the first n terms of the following sequences (n requested from the user):<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19872 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo11.png\" alt=\"algorithm continued\" width=\"646\" height=\"79\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo11.png 646w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo11-300x37.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo11-18x2.png 18w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3533995 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3533995\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-477ea53\" data-id=\"477ea53\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f47779b elementor-widget elementor-widget-toggle\" data-id=\"f47779b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2561\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2561\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2561\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2561\"><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19873 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo12.png\" alt=\"algorithm continued\" width=\"725\" height=\"312\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo12.png 725w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo12-300x129.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo12-18x8.png 18w\" sizes=\"(max-width: 725px) 100vw, 725px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f8e5045 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f8e5045\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e0d1d3c\" data-id=\"e0d1d3c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fc77d25 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"fc77d25\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d081752 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d081752\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4e96544\" data-id=\"4e96544\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-dd7bd1e elementor-widget elementor-widget-heading\" data-id=\"dd7bd1e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-8\"><\/span>Exercise 8<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-54fd92f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"54fd92f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2590390\" data-id=\"2590390\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-729623b elementor-widget elementor-widget-text-editor\" data-id=\"729623b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Write an algorithm that calculates the first n prime numbers.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f06445c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f06445c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-9c54701\" data-id=\"9c54701\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4fa0acc elementor-widget elementor-widget-toggle\" data-id=\"4fa0acc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-8341\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-8341\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-8341\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-8341\"><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19874 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo13.png\" alt=\"prime number algorithm\" width=\"739\" height=\"473\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo13.png 739w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo13-300x192.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo13-18x12.png 18w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-c4897c6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c4897c6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-10b513c\" data-id=\"10b513c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-da78a2e elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"da78a2e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-1db54b6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"1db54b6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-35eee90\" data-id=\"35eee90\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-d586a57 elementor-widget elementor-widget-heading\" data-id=\"d586a57\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-9\"><\/span>Exercise 9<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-592804f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"592804f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0ca7734\" data-id=\"0ca7734\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-20536c1 elementor-widget elementor-widget-text-editor\" data-id=\"20536c1\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19875 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo14.png\" alt=\"pascal&#039;s triangle algorithm\" width=\"745\" height=\"166\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo14.png 745w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo14-300x67.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo14-18x4.png 18w\" sizes=\"(max-width: 745px) 100vw, 745px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d01c15c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d01c15c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6f9488d\" data-id=\"6f9488d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8f19784 elementor-widget elementor-widget-toggle\" data-id=\"8f19784\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1501\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1501\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1501\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1501\"><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-19876 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo15.png\" alt=\"pascal&#039;s triangle algorithm\" width=\"759\" height=\"332\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo15.png 759w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo15-300x131.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo15-18x8.png 18w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b3d843f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b3d843f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1568227\" data-id=\"1568227\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0721b6a elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"0721b6a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5954514 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5954514\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6079c18\" data-id=\"6079c18\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f1e8ef0 elementor-widget elementor-widget-heading\" data-id=\"f1e8ef0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-10\"><\/span>Exercise 10<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ba7efdf elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ba7efdf\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6595e0d\" data-id=\"6595e0d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1536d49 elementor-widget elementor-widget-text-editor\" data-id=\"1536d49\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>A positive integer is said <em>Perfect <\/em>if it is equal to the sum of its divisors (except itself). For example 6 is perfect, because 6 = 1 + 2 + 3; similarly 28 is perfect, because 28 = 1 + 2 + 4 + 7 + 14.<\/p><p>Write a perfect Boolean function for an integer n. To optimise.<\/p><p>Make a perfect_riddle procedure which searches for and displays, using a sieve, the perfect numbers on an interval from 1 to <em>M <\/em>.<\/p><p>We plan to store for each integer the sum of its divisors, a sum which will be calculated during the sift: the principle of the sift is, for each integer \u00a0<em>i \u00a0<\/em>of the interval, to go through the multiples of <em>i <\/em>to which we add the divisor <em>i<\/em>.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-418716f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"418716f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-14bcd8f\" data-id=\"14bcd8f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9acaa6e elementor-widget elementor-widget-toggle\" data-id=\"9acaa6e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1621\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1621\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1621\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1621\"><p>Here is a fairly simple algorithm to think of for finding a perfect number.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20204 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-1.png\" alt=\"perfect number\" width=\"422\" height=\"141\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-1.png 422w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-1-300x100.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo1-1-18x6.png 18w\" sizes=\"(max-width: 422px) 100vw, 422px\" \/><\/p><p>We can also initialize <em>s <\/em>to 1 and start the loop at 2, but be careful the function must return false for <em>i <\/em>= 1; we must then add a test to the initialization.<\/p><p>We can optimize the function by noting that if <em>i <\/em>split <em>not<\/em>, SO (<em>not <\/em>div <em>i<\/em>) is also a divisor since <em>i <\/em>(<em>not <\/em>div <em>i<\/em>) = <em>not<\/em>.<\/p><p>Just vary <em>i <\/em>from 2 to \u221a<em>not <\/em>: if <em>i <\/em>is a divisor, then the divisor (<em>not <\/em>div <em>i<\/em>) is in the interval \u221a<em>not <\/em>To <em>not <\/em>; so we have all the divisors.<\/p><p>You have to think about starting at 2 so as not to add <em>not<\/em>. There is also a problem if <em>not <\/em>is a square: we will have added the divisor twice <em>r <\/em>= \u221a<em>not<\/em>.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20206 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-1.png\" alt=\"perfect number\" width=\"537\" height=\"324\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-1.png 537w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-1-300x181.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo2-1-18x12.png 18w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/p><p>Here is an algorithm for perfect_screen:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20207 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-1.png\" alt=\"perfect number sieve\" width=\"474\" height=\"425\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-1.png 474w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-1-300x269.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo3-1-13x12.png 13w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><\/p><p>The perfect numbers between 1 and 10,000,000 are 6, 28, 496, 8128.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-64777c5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"64777c5\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-1ccfaed\" data-id=\"1ccfaed\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7fd604c elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"7fd604c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-e326ac4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"e326ac4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-4ee0922\" data-id=\"4ee0922\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-de28aa9 elementor-widget elementor-widget-heading\" data-id=\"de28aa9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-11\"><\/span>Exercise 11<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-83730de elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"83730de\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8c677b4\" data-id=\"8c677b4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-170d4d5 elementor-widget elementor-widget-text-editor\" data-id=\"170d4d5\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Write a function that returns the number of occurrences of the maximum value present in an unsorted array. Build the algorithm in 0(n).<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9381eb4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9381eb4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3749910\" data-id=\"3749910\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-683c119 elementor-widget elementor-widget-toggle\" data-id=\"683c119\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1091\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1091\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1091\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1091\"><p>It is possible to do it as a two-stroke, we will have a <a href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/complexity-in-time\/\">complexity<\/a> of 2n=O(n)<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20208 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-1.png\" alt=\"maximum number algorithm\" width=\"449\" height=\"241\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-1.png 449w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-1-300x161.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo4-1-18x10.png 18w\" sizes=\"(max-width: 449px) 100vw, 449px\" \/><\/p><p>Or to do everything in a single loop:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20209 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-1.png\" alt=\"maximum number algorithm\" width=\"438\" height=\"181\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-1.png 438w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-1-300x124.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo5-1-18x7.png 18w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-0eba6fa elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"0eba6fa\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d6c9564\" data-id=\"d6c9564\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-83da76a elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"83da76a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-00f42b3 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"00f42b3\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-04a95a3\" data-id=\"04a95a3\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-df86188 elementor-widget elementor-widget-heading\" data-id=\"df86188\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-12\"><\/span>Exercise 12<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-505b3b4 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"505b3b4\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-7699781\" data-id=\"7699781\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3bf6af3 elementor-widget elementor-widget-text-editor\" data-id=\"3bf6af3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We consider a square <em>Q <\/em>in which a large number of points are randomly positioned. The ratio between the number of points appearing in the circle inscribed in <em>Q <\/em>and the number of points drawn approaches the ratio between the surface of the disc inscribed in <em>Q <\/em>and the surface of the square <em>Q<\/em>. We deduce an approximate value of <em>\u03c0<\/em>. This method is called a Monte Carlo simulation (very useful in finance!).<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-aa41ad6 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"aa41ad6\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0ca65bd\" data-id=\"0ca65bd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f58367b elementor-widget elementor-widget-toggle\" data-id=\"f58367b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2571\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2571\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2571\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2571\"><p>That is \u00a0<em>r \u00a0<\/em>the radius of the circle. The area of the circle is \u00a0<em>\u03c0r<\/em><sup>2<\/sup> \u00a0and the area of the square is 4<em>r<\/em><sup>2<\/sup>. To simplify we take <em>r <\/em>= 1, and we limit ourselves to the quarter plane R<sup>+<\/sup> \u00d7R<sup>+<\/sup> .<\/p><p>random(m) provides an integer between 0 and <em>m-<\/em>1, while random without parameters provides a real between 0 and 1.<\/p><p>To know if a point (<em>x,y<\/em>) \u2208 at the quarter circle we test if \u221a(<em>x<\/em>\u00b2 + <em>y<\/em>\u00b2) \u2264 1.<\/p><p>As calculating the square root is expensive, we simply do the equivalent test (<em>x<\/em>\u00b2 + <em>y<\/em>\u00b2) \u2264 1. For this we can use the sqr function which is more optimized than x*x.<\/p><p><em>not <\/em>is the total number of points drawn (all in the quarter square); <em>vs\u00a0<\/em>is the number of these points that is in the quarter circle.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20210 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-1.png\" alt=\"algorithm pi calculation monte carlo\" width=\"386\" height=\"193\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-1.png 386w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-1-300x150.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/algo6-1-18x9.png 18w\" sizes=\"(max-width: 386px) 100vw, 386px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Algorithmic Wiki home page Corrected exercises on algorithmic structures The following corrected exercises relate to algorithmic structures, control structures and \u2026 <\/p>","protected":false},"author":1,"featured_media":0,"parent":1062,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-16433","page","type-page","status-publish","hentry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/16433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/comments?post=16433"}],"version-history":[{"count":27,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/16433\/revisions"}],"predecessor-version":[{"id":21203,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/16433\/revisions\/21203"}],"up":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/1062"}],"wp:attachment":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/media?parent=16433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}