<commit_before>"""
Project Euler Problem 5
=======================

2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers
from 1 to 20?
"""

from functools import reduce
from math import gcd


def divisible_by(factors):
    """
    Takes a list of integers and returns the smallest number that
    can be divided by each without any remainder.

    This works because:
        lcm(x, y) == (x * y) / gcd(x, y)

    And with the commutative property of multiplication:
        lcm(x, y, z) == lcm(x, lcm(y, z))
    """
    return reduce(lambda x, y: x * y // gcd(x, y), factors)


def test_divible_by():
    assert divisible_by(range(1, 10 + 1)) == 2520


print(divisible_by(range(1, 20 + 1)))
<commit_msg>Small refactor to problem 005<commit_after>"""
Project Euler Problem 5
=======================

2520 is the smallest number that can be divided by each of the numbers
from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers
from 1 to 20?
"""

from functools import reduce
from fractions import gcd


def lcm(x, y):
    """
    Takes two integers and returns the `Least Common Multiple`.
    """
    return x * y // gcd(x, y)


def lcm_iter(factors):
    """
    Takes an iterable of integers and returns the smallest number that
    can be divided by each without any remainder.

    The reduce works because of the commutative property of multiplication:
        lcm(x, y, z) == lcm(x, lcm(y, z))
    """
    return reduce(lcm, factors)


def test_divible_by():
    assert lcm_iter(range(1, 10 + 1)) == 2520


print(lcm_iter(range(1, 20 + 1)))
{'fraction_non_alphanumeric': 0.1142527409117138, 'fraction_numerical': 0.02827466820542412, 'mean_word_length': 3.389873417721519, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3443454', 'n_tokens_mistral': 590, 'n_tokens_neox': 522, 'n_words': 237}