From e54e7afd6cb8a3ad933039222186588b3cde25e8 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sat, 2 Dec 2023 07:26:47 +0100 Subject: [PATCH] mul() equivalent to sum() --- src/tools/math.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tools/math.py b/src/tools/math.py index f98c5b7..6a58baf 100644 --- a/src/tools/math.py +++ b/src/tools/math.py @@ -1,6 +1,7 @@ from __future__ import annotations import math from decimal import Decimal, ROUND_HALF_UP +from typing import Iterable def round_half_up(number: int | float) -> int: @@ -16,3 +17,12 @@ def get_factors(num: int) -> set: f.add(num // x) return f + + +def mul(ints: Iterable[int]) -> int: + """similar to sum(), just for multiplication""" + ret = 1 + for x in ints: + ret *= x + + return ret