From 8c43dbdd46b520e8cd0471951b143827ce73ad58 Mon Sep 17 00:00:00 2001 From: quant12345 Date: Mon, 11 Sep 2023 12:16:59 +0500 Subject: [PATCH 1/4] Euler 070 partial replacement of numpy loops. --- project_euler/problem_070/sol1.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/project_euler/problem_070/sol1.py b/project_euler/problem_070/sol1.py index 273f37efc5fc..ca34f2016e0e 100644 --- a/project_euler/problem_070/sol1.py +++ b/project_euler/problem_070/sol1.py @@ -29,6 +29,7 @@ https://en.wikipedia.org/wiki/Euler's_totient_function#Euler's_product_formula """ from __future__ import annotations +import numpy as np def get_totients(max_one: int) -> list[int]: @@ -42,17 +43,14 @@ def get_totients(max_one: int) -> list[int]: >>> get_totients(10) [0, 1, 1, 2, 2, 4, 2, 6, 4, 6] """ - totients = [0] * max_one - - for i in range(0, max_one): - totients[i] = i + totients = np.arange(max_one) for i in range(2, max_one): if totients[i] == i: - for j in range(i, max_one, i): - totients[j] -= totients[j] // i + x = np.arange(i, max_one, i) # array of indexes to select + totients[x] -= totients[x] // i - return totients + return totients.tolist() def has_same_digits(num1: int, num2: int) -> bool: From b8518c5ec817dfebb11a3226c6b4902cb3aaa0ff Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 11 Sep 2023 10:36:28 +0200 Subject: [PATCH 2/4] Update project_euler/problem_070/sol1.py --- project_euler/problem_070/sol1.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project_euler/problem_070/sol1.py b/project_euler/problem_070/sol1.py index ca34f2016e0e..f1114a280a31 100644 --- a/project_euler/problem_070/sol1.py +++ b/project_euler/problem_070/sol1.py @@ -29,6 +29,7 @@ https://en.wikipedia.org/wiki/Euler's_totient_function#Euler's_product_formula """ from __future__ import annotations + import numpy as np From 700e74dd15154b5c60b1796b8f83fb5a6ed0a81c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 11 Sep 2023 12:02:27 +0200 Subject: [PATCH 3/4] project_euler.yml: Upgrade actions/checkout@v4 and add numpy --- .github/workflows/project_euler.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/project_euler.yml b/.github/workflows/project_euler.yml index 460938219c14..c57ac17f4739 100644 --- a/.github/workflows/project_euler.yml +++ b/.github/workflows/project_euler.yml @@ -14,7 +14,7 @@ jobs: project-euler: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: 3.x @@ -26,14 +26,14 @@ jobs: validate-solutions: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: 3.x - name: Install pytest and requests run: | python -m pip install --upgrade pip - python -m pip install --upgrade pytest requests + python -m pip install --upgrade numpy pytest requests - run: pytest scripts/validate_solutions.py env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 89a1a8188531d4ea63febb4e68e6b57dda183b7d Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 11 Sep 2023 12:05:37 +0200 Subject: [PATCH 4/4] Update project_euler.yml --- .github/workflows/project_euler.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/project_euler.yml b/.github/workflows/project_euler.yml index c57ac17f4739..7bbccf76e192 100644 --- a/.github/workflows/project_euler.yml +++ b/.github/workflows/project_euler.yml @@ -21,7 +21,7 @@ jobs: - name: Install pytest and pytest-cov run: | python -m pip install --upgrade pip - python -m pip install --upgrade pytest pytest-cov + python -m pip install --upgrade numpy pytest pytest-cov - run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/ validate-solutions: runs-on: ubuntu-latest