Python/maths/is_square_free.py
pre-commit-ci[bot] bc8df6de31
[pre-commit.ci] pre-commit autoupdate (#11322)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2)
- [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-03-13 07:52:41 +01:00

41 lines
946 B
Python

"""
References: wikipedia:square free number
psf/black : True
ruff : True
"""
from __future__ import annotations
def is_square_free(factors: list[int]) -> bool:
"""
# doctest: +NORMALIZE_WHITESPACE
This functions takes a list of prime factors as input.
returns True if the factors are square free.
>>> is_square_free([1, 1, 2, 3, 4])
False
These are wrong but should return some value
it simply checks for repetition in the numbers.
>>> is_square_free([1, 3, 4, 'sd', 0.0])
True
>>> is_square_free([1, 0.5, 2, 0.0])
True
>>> is_square_free([1, 2, 2, 5])
False
>>> is_square_free('asd')
True
>>> is_square_free(24)
Traceback (most recent call last):
...
TypeError: 'int' object is not iterable
"""
return len(set(factors)) == len(factors)
if __name__ == "__main__":
import doctest
doctest.testmod()