|
3 | 3 | { |
4 | 4 | "cell_type": "markdown", |
5 | 5 | "metadata": { |
6 | | - "id": "JLOS92ZAhfFj" |
| 6 | + "id": "G3MMAcssHTML" |
7 | 7 | }, |
8 | 8 | "source": [ |
9 | | - "Project: /gemma/_project.yaml\n", |
10 | | - "Book: /gemma/_book.yaml\n", |
11 | | - "\n", |
12 | | - "<link rel=\"stylesheet\" href=\"/site-assets/css/style.css\">\n", |
13 | | - "\n", |
14 | | - "<!-- DO NOT EDIT! Automatically generated file. -->" |
| 9 | + "<link rel=\"stylesheet\" href=\"/site-assets/css/gemma.css\">\n", |
| 10 | + "<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css2?family=Google+Symbols:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200\" />" |
15 | 11 | ] |
16 | 12 | }, |
17 | 13 | { |
|
569 | 565 | "outputs": [ |
570 | 566 | { |
571 | 567 | "data": { |
572 | | - "text/markdown": "<font size='+1' color='brown'>🙋♂️<blockquote>Tell me, in a few words, how to compute all prime numbers up to 1000?</blockquote></font><font size='+1' color='teal'>🤖\n\n> **Sieve of Eratosthenes.** \n> <end_of_turn>\n</font>", |
| 568 | + "text/markdown": [ |
| 569 | + "<font size='+1' color='brown'>🙋♂️<blockquote>Tell me, in a few words, how to compute all prime numbers up to 1000?</blockquote></font><font size='+1' color='teal'>🤖\n", |
| 570 | + "\n", |
| 571 | + "> **Sieve of Eratosthenes.** \n", |
| 572 | + "> <end_of_turn>\n", |
| 573 | + "</font>" |
| 574 | + ], |
573 | 575 | "text/plain": [ |
574 | 576 | "<IPython.core.display.Markdown object>" |
575 | 577 | ] |
|
603 | 605 | "outputs": [ |
604 | 606 | { |
605 | 607 | "data": { |
606 | | - "text/markdown": "<font size='+1' color='brown'>🙋♂️<blockquote>Now in Python! No numpy, please!</blockquote></font><font size='+1' color='teal'>🤖\n\n> ```python\n> def sieve_of_eratosthenes(n):\n> \"\"\"Returns a list of prime numbers up to n.\"\"\"\n> primes = [True] * (n + 1)\n> primes[0] = primes[1] = False\n> for i in range(2, int(n**0.5) + 1):\n> if primes[i]:\n> for j in range(i * i, n + 1, i):\n> primes[j] = False\n> return [i for i, is_prime in enumerate(primes) if is_prime]\n> \n> primes = sieve_of_eratosthenes(1000)\n> print(primes)\n> ```\n> \n> **Explanation:**\n> \n> 1. **Initialization:**\n> - `primes = [True] * (n + 1)`: Creates a list `primes` of boolean values, initially assuming all numbers are prime.\n> - `primes[0] = primes[1] = False`: Sets 0 and 1 as non-prime.\n> \n> 2. **Iteration:**\n> - `for i in range(2, int(n**0.5) + 1):`: Iterates from 2 to the square root of `n`. We only need to check up to the square root because any composite number must have a prime factor less than or equal to its square root.\n> - `if primes[i]:`: If `i` is marked as prime:\n> - `for j in range(i * i, n + 1, i):`: Marks all multiples of `i` as non-prime.\n> \n> 3. **Result:**\n> - `return [i for i, is_prime in enumerate(primes) if is_prime]`: Creates a list of indices where `primes[i]` is True, representing the prime numbers.\n> \n> \n> Let me know if you'd like a more detailed explanation of any part! \n> <end_of_turn>\n</font>", |
| 608 | + "text/markdown": [ |
| 609 | + "<font size='+1' color='brown'>🙋♂️<blockquote>Now in Python! No numpy, please!</blockquote></font><font size='+1' color='teal'>🤖\n", |
| 610 | + "\n", |
| 611 | + "> ```python\n", |
| 612 | + "> def sieve_of_eratosthenes(n):\n", |
| 613 | + "> \"\"\"Returns a list of prime numbers up to n.\"\"\"\n", |
| 614 | + "> primes = [True] * (n + 1)\n", |
| 615 | + "> primes[0] = primes[1] = False\n", |
| 616 | + "> for i in range(2, int(n**0.5) + 1):\n", |
| 617 | + "> if primes[i]:\n", |
| 618 | + "> for j in range(i * i, n + 1, i):\n", |
| 619 | + "> primes[j] = False\n", |
| 620 | + "> return [i for i, is_prime in enumerate(primes) if is_prime]\n", |
| 621 | + "> \n", |
| 622 | + "> primes = sieve_of_eratosthenes(1000)\n", |
| 623 | + "> print(primes)\n", |
| 624 | + "> ```\n", |
| 625 | + "> \n", |
| 626 | + "> **Explanation:**\n", |
| 627 | + "> \n", |
| 628 | + "> 1. **Initialization:**\n", |
| 629 | + "> - `primes = [True] * (n + 1)`: Creates a list `primes` of boolean values, initially assuming all numbers are prime.\n", |
| 630 | + "> - `primes[0] = primes[1] = False`: Sets 0 and 1 as non-prime.\n", |
| 631 | + "> \n", |
| 632 | + "> 2. **Iteration:**\n", |
| 633 | + "> - `for i in range(2, int(n**0.5) + 1):`: Iterates from 2 to the square root of `n`. We only need to check up to the square root because any composite number must have a prime factor less than or equal to its square root.\n", |
| 634 | + "> - `if primes[i]:`: If `i` is marked as prime:\n", |
| 635 | + "> - `for j in range(i * i, n + 1, i):`: Marks all multiples of `i` as non-prime.\n", |
| 636 | + "> \n", |
| 637 | + "> 3. **Result:**\n", |
| 638 | + "> - `return [i for i, is_prime in enumerate(primes) if is_prime]`: Creates a list of indices where `primes[i]` is True, representing the prime numbers.\n", |
| 639 | + "> \n", |
| 640 | + "> \n", |
| 641 | + "> Let me know if you'd like a more detailed explanation of any part! \n", |
| 642 | + "> <end_of_turn>\n", |
| 643 | + "</font>" |
| 644 | + ], |
607 | 645 | "text/plain": [ |
608 | 646 | "<IPython.core.display.Markdown object>" |
609 | 647 | ] |
|
627 | 665 | "outputs": [ |
628 | 666 | { |
629 | 667 | "data": { |
630 | | - "text/markdown": "<font size='+1' color='brown'>🙋♂️<blockquote>Thank you, it works! Can you explain the code in French?</blockquote></font><font size='+1' color='teal'>🤖\n\n> Bien sûr ! Voici une explication du code en français :\n> \n> ```python\n> def sieve_of_eratosthenes(n):\n> \"\"\"Retourne une liste de nombres premiers jusqu'à n.\"\"\"\n> primes = [True] * (n + 1)\n> primes[0] = primes[1] = False\n> for i in range(2, int(n**0.5) + 1):\n> if primes[i]:\n> for j in range(i * i, n + 1, i):\n> primes[j] = False\n> return [i for i, is_prime in enumerate(primes) if is_prime]\n> \n> primes = sieve_of_eratosthenes(1000)\n> print(primes)\n> ```\n> \n> **Explication:**\n> \n> 1. **Initialisation:**\n> - `primes = [True] * (n + 1)`: Crée une liste `primes` de valeurs booléennes, initialement supposant que tous les nombres sont premiers.\n> - `primes[0] = primes[1] = False`: Définit 0 et 1 comme non-premiers.\n> \n> 2. **Itération:**\n> - `for i in range(2, int(n**0.5) + 1):`: Itère de 2 jusqu'à la racine carrée de `n`. Nous ne devons vérifier que jusqu'à la racine carrée car tout nombre composite doit avoir un facteur premier inférieur ou égal à sa racine carrée.\n> - `if primes[i]:`: Si `i` est considéré comme premier:\n> - `for j in range(i * i, n + 1, i):`: Marquer tous les multiples de `i` comme non-premiers.\n> \n> 3. **Resultat:**\n> - `return [i for i, is_prime in enumerate(primes) if is_prime]`: Crée une liste des indices où `primes[i]` est vrai, représentant les nombres premiers.\n> \n> \n> N'hésitez pas à me demander si vous avez besoin d'une explication plus détaillée de quelque chose! \n> <end_of_turn>\n</font>", |
| 668 | + "text/markdown": [ |
| 669 | + "<font size='+1' color='brown'>🙋♂️<blockquote>Thank you, it works! Can you explain the code in French?</blockquote></font><font size='+1' color='teal'>🤖\n", |
| 670 | + "\n", |
| 671 | + "> Bien sûr ! Voici une explication du code en français :\n", |
| 672 | + "> \n", |
| 673 | + "> ```python\n", |
| 674 | + "> def sieve_of_eratosthenes(n):\n", |
| 675 | + "> \"\"\"Retourne une liste de nombres premiers jusqu'à n.\"\"\"\n", |
| 676 | + "> primes = [True] * (n + 1)\n", |
| 677 | + "> primes[0] = primes[1] = False\n", |
| 678 | + "> for i in range(2, int(n**0.5) + 1):\n", |
| 679 | + "> if primes[i]:\n", |
| 680 | + "> for j in range(i * i, n + 1, i):\n", |
| 681 | + "> primes[j] = False\n", |
| 682 | + "> return [i for i, is_prime in enumerate(primes) if is_prime]\n", |
| 683 | + "> \n", |
| 684 | + "> primes = sieve_of_eratosthenes(1000)\n", |
| 685 | + "> print(primes)\n", |
| 686 | + "> ```\n", |
| 687 | + "> \n", |
| 688 | + "> **Explication:**\n", |
| 689 | + "> \n", |
| 690 | + "> 1. **Initialisation:**\n", |
| 691 | + "> - `primes = [True] * (n + 1)`: Crée une liste `primes` de valeurs booléennes, initialement supposant que tous les nombres sont premiers.\n", |
| 692 | + "> - `primes[0] = primes[1] = False`: Définit 0 et 1 comme non-premiers.\n", |
| 693 | + "> \n", |
| 694 | + "> 2. **Itération:**\n", |
| 695 | + "> - `for i in range(2, int(n**0.5) + 1):`: Itère de 2 jusqu'à la racine carrée de `n`. Nous ne devons vérifier que jusqu'à la racine carrée car tout nombre composite doit avoir un facteur premier inférieur ou égal à sa racine carrée.\n", |
| 696 | + "> - `if primes[i]:`: Si `i` est considéré comme premier:\n", |
| 697 | + "> - `for j in range(i * i, n + 1, i):`: Marquer tous les multiples de `i` comme non-premiers.\n", |
| 698 | + "> \n", |
| 699 | + "> 3. **Resultat:**\n", |
| 700 | + "> - `return [i for i, is_prime in enumerate(primes) if is_prime]`: Crée une liste des indices où `primes[i]` est vrai, représentant les nombres premiers.\n", |
| 701 | + "> \n", |
| 702 | + "> \n", |
| 703 | + "> N'hésitez pas à me demander si vous avez besoin d'une explication plus détaillée de quelque chose! \n", |
| 704 | + "> <end_of_turn>\n", |
| 705 | + "</font>" |
| 706 | + ], |
631 | 707 | "text/plain": [ |
632 | 708 | "<IPython.core.display.Markdown object>" |
633 | 709 | ] |
|
651 | 727 | "outputs": [ |
652 | 728 | { |
653 | 729 | "data": { |
654 | | - "text/markdown": "<font size='+1' color='brown'>🙋♂️<blockquote>Great! Now add those explanations as comments in the code.</blockquote></font><font size='+1' color='teal'>🤖\n\n> ```python\n> def sieve_of_eratosthenes(n):\n> \"\"\"Retourne une liste de nombres premiers jusqu'à n.\"\"\"\n> # Initialise une liste de boolean avec True pour tous les nombres de 0 à n\n> primes = [True] * (n + 1)\n> # Définit 0 et 1 comme non-premiers\n> primes[0] = primes[1] = False\n> # Itère de 2 à la racine carrée de n\n> for i in range(2, int(n**0.5) + 1):\n> # Si i est considéré comme premier\n> if primes[i]:\n> # Itère sur tous les multiples de i\n> for j in range(i * i, n + 1, i):\n> # Définit les multiples de i comme non-premiers\n> primes[j] = False\n> # Retourne la liste des indices des nombres premiers\n> return [i for i, is_prime in enumerate(primes) if is_prime]\n> \n> primes = sieve_of_eratosthenes(1000)\n> print(primes)\n> ```\n> \n> **Explication:**\n> \n> * **Initialisation:**\n> * `primes = [True] * (n + 1)`: Crée une liste `primes` de valeurs booléennes, initialement supposant que tous les nombres sont premiers.\n> * `primes[0] = primes[1] = False`: Définit 0 et 1 comme non-premiers.\n> * **Itération:**\n> * `for i in range(2, int(n**0.5) + 1):`: Itère de 2 jusqu'à la racine carrée de `n`. Nous ne devons vérifier que jusqu'à la racine carrée car tout nombre composite doit avoir un facteur premier inférieur ou égal à sa racine carrée.\n> * `if primes[i]:`: Si `i` est considéré comme premier:\n> * `for j in range(i * i, n + 1, i):`: Marquer tous les multiples de `i` comme non-premiers.\n> * **Resultat:**\n> * `return [i for i, is_prime in enumerate(primes) if is_prime]`: Crée une liste des indices où `primes[i]` est vrai, représentant les nombres premiers. \n> \n> \n> \n> <end_of_turn>\n</font>", |
| 730 | + "text/markdown": [ |
| 731 | + "<font size='+1' color='brown'>🙋♂️<blockquote>Great! Now add those explanations as comments in the code.</blockquote></font><font size='+1' color='teal'>🤖\n", |
| 732 | + "\n", |
| 733 | + "> ```python\n", |
| 734 | + "> def sieve_of_eratosthenes(n):\n", |
| 735 | + "> \"\"\"Retourne une liste de nombres premiers jusqu'à n.\"\"\"\n", |
| 736 | + "> # Initialise une liste de boolean avec True pour tous les nombres de 0 à n\n", |
| 737 | + "> primes = [True] * (n + 1)\n", |
| 738 | + "> # Définit 0 et 1 comme non-premiers\n", |
| 739 | + "> primes[0] = primes[1] = False\n", |
| 740 | + "> # Itère de 2 à la racine carrée de n\n", |
| 741 | + "> for i in range(2, int(n**0.5) + 1):\n", |
| 742 | + "> # Si i est considéré comme premier\n", |
| 743 | + "> if primes[i]:\n", |
| 744 | + "> # Itère sur tous les multiples de i\n", |
| 745 | + "> for j in range(i * i, n + 1, i):\n", |
| 746 | + "> # Définit les multiples de i comme non-premiers\n", |
| 747 | + "> primes[j] = False\n", |
| 748 | + "> # Retourne la liste des indices des nombres premiers\n", |
| 749 | + "> return [i for i, is_prime in enumerate(primes) if is_prime]\n", |
| 750 | + "> \n", |
| 751 | + "> primes = sieve_of_eratosthenes(1000)\n", |
| 752 | + "> print(primes)\n", |
| 753 | + "> ```\n", |
| 754 | + "> \n", |
| 755 | + "> **Explication:**\n", |
| 756 | + "> \n", |
| 757 | + "> * **Initialisation:**\n", |
| 758 | + "> * `primes = [True] * (n + 1)`: Crée une liste `primes` de valeurs booléennes, initialement supposant que tous les nombres sont premiers.\n", |
| 759 | + "> * `primes[0] = primes[1] = False`: Définit 0 et 1 comme non-premiers.\n", |
| 760 | + "> * **Itération:**\n", |
| 761 | + "> * `for i in range(2, int(n**0.5) + 1):`: Itère de 2 jusqu'à la racine carrée de `n`. Nous ne devons vérifier que jusqu'à la racine carrée car tout nombre composite doit avoir un facteur premier inférieur ou égal à sa racine carrée.\n", |
| 762 | + "> * `if primes[i]:`: Si `i` est considéré comme premier:\n", |
| 763 | + "> * `for j in range(i * i, n + 1, i):`: Marquer tous les multiples de `i` comme non-premiers.\n", |
| 764 | + "> * **Resultat:**\n", |
| 765 | + "> * `return [i for i, is_prime in enumerate(primes) if is_prime]`: Crée une liste des indices où `primes[i]` est vrai, représentant les nombres premiers. \n", |
| 766 | + "> \n", |
| 767 | + "> \n", |
| 768 | + "> \n", |
| 769 | + "> <end_of_turn>\n", |
| 770 | + "</font>" |
| 771 | + ], |
655 | 772 | "text/plain": [ |
656 | 773 | "<IPython.core.display.Markdown object>" |
657 | 774 | ] |
|
0 commit comments