2019-07-21 08:35:42 +00:00
|
|
|
"""
|
|
|
|
References: wikipedia:square free number
|
2023-03-16 12:31:29 +00:00
|
|
|
psf/black : True
|
|
|
|
ruff : True
|
2019-07-21 08:35:42 +00:00
|
|
|
"""
|
2020-09-23 11:30:13 +00:00
|
|
|
from __future__ import annotations
|
2019-07-21 08:35:42 +00:00
|
|
|
|
|
|
|
|
2020-09-23 11:30:13 +00:00
|
|
|
def is_square_free(factors: list[int]) -> bool:
|
2019-07-21 08:35:42 +00:00
|
|
|
"""
|
|
|
|
# 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
|
2020-05-22 06:10:11 +00:00
|
|
|
|
2019-07-21 08:35:42 +00:00
|
|
|
These are wrong but should return some value
|
2022-10-17 19:59:25 +00:00
|
|
|
it simply checks for repetition in the numbers.
|
2019-07-21 08:35:42 +00:00
|
|
|
>>> is_square_free([1, 3, 4, 'sd', 0.0])
|
|
|
|
True
|
2020-05-22 06:10:11 +00:00
|
|
|
|
2019-07-21 08:35:42 +00:00
|
|
|
>>> 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()
|