jugaadcode 0.1.13__tar.gz → 0.1.15__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/PKG-INFO +1 -1
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/pyproject.toml +1 -1
- jugaadcode-0.1.15/src/jugaadcode/factorial_with_trailing_zeros.py +83 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/trailing_zeros.py +3 -1
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode.egg-info/PKG-INFO +1 -1
- jugaadcode-0.1.13/src/jugaadcode/factorial_with_trailing_zeros.py +0 -71
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/README.md +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/setup.cfg +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/__init__.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/anagram.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/armstrong.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/binary_search.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/bubble_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/capitalize_words.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/character_frequency.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/climbing_stairs.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/coin_change.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/count_vowels.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/counting_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/duplicate_number.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/even_odd.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/factorial.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/factorial_trailing_zeros_direct.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/fibonacci.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/find_max.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/find_min.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/first_non_repeating.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/gcd.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/harshad_number.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/input_utils.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/insertion_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/kth_largest.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/lcm.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/linear_search.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/longest_consecutive.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/longest_word.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/matrix_transpose.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/maximum_subarray.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/merge_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/move_zeros.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/pair_with_difference.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/palindrome.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/perfect_number.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/power.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/prime.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/quick_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/remove_duplicates_array.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/remove_duplicates_string.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/reverse_linked_list.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/reverse_number.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/reverse_string.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/second_largest.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/selection_sort.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/strong_number.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/subsequence.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/sum_of_digits.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/two_sum.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/valid_parentheses.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode/word_count.py +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode.egg-info/SOURCES.txt +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode.egg-info/dependency_links.txt +0 -0
- {jugaadcode-0.1.13 → jugaadcode-0.1.15}/src/jugaadcode.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from .trailing_zeros import trailing_zeros
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def factorial_with_trailing_zeros(*args):
|
|
6
|
+
"""
|
|
7
|
+
Find the smallest non-negative integer n whose factorial
|
|
8
|
+
contains exactly the requested number of trailing zeros.
|
|
9
|
+
|
|
10
|
+
Examples:
|
|
11
|
+
factorial_with_trailing_zeros(0) -> 0
|
|
12
|
+
factorial_with_trailing_zeros(1) -> 5
|
|
13
|
+
factorial_with_trailing_zeros(6) -> 25
|
|
14
|
+
factorial_with_trailing_zeros(5) -> None
|
|
15
|
+
factorial_with_trailing_zeros([1, 2, 6]) -> [5, 10, 25]
|
|
16
|
+
factorial_with_trailing_zeros((1, 2, 6)) -> (5, 10, 25)
|
|
17
|
+
factorial_with_trailing_zeros(1, 2, 6) -> (5, 10, 25)
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
int | None: Result for a single input.
|
|
21
|
+
list: Results for a list or other iterable.
|
|
22
|
+
tuple: Results for a tuple or multiple positional inputs.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def find_number(zeros):
|
|
26
|
+
if isinstance(zeros, bool) or not isinstance(zeros, int):
|
|
27
|
+
raise TypeError("Input must be an integer.")
|
|
28
|
+
|
|
29
|
+
if zeros < 0:
|
|
30
|
+
raise ValueError("Number of trailing zeros must be non-negative.")
|
|
31
|
+
|
|
32
|
+
low = 0
|
|
33
|
+
high = max(5, zeros * 5)
|
|
34
|
+
|
|
35
|
+
while low < high:
|
|
36
|
+
mid = (low + high) // 2
|
|
37
|
+
|
|
38
|
+
if trailing_zeros(mid) < zeros:
|
|
39
|
+
low = mid + 1
|
|
40
|
+
else:
|
|
41
|
+
high = mid
|
|
42
|
+
|
|
43
|
+
if trailing_zeros(low) == zeros:
|
|
44
|
+
return low
|
|
45
|
+
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
# Interactive input
|
|
49
|
+
if not args:
|
|
50
|
+
value = input(
|
|
51
|
+
"Enter the required number of trailing zeros: "
|
|
52
|
+
).strip()
|
|
53
|
+
|
|
54
|
+
numbers = [int(item.strip()) for item in value.split(",")]
|
|
55
|
+
results = [find_number(number) for number in numbers]
|
|
56
|
+
|
|
57
|
+
return results[0] if len(results) == 1 else results
|
|
58
|
+
|
|
59
|
+
# Multiple positional inputs
|
|
60
|
+
if len(args) > 1:
|
|
61
|
+
return tuple(find_number(number) for number in args)
|
|
62
|
+
|
|
63
|
+
value = args[0]
|
|
64
|
+
|
|
65
|
+
# Single integer
|
|
66
|
+
if isinstance(value, int) and not isinstance(value, bool):
|
|
67
|
+
return find_number(value)
|
|
68
|
+
|
|
69
|
+
# Reject strings and bytes
|
|
70
|
+
if isinstance(value, (str, bytes, bytearray)):
|
|
71
|
+
raise TypeError("Input must be an integer or an iterable of integers.")
|
|
72
|
+
|
|
73
|
+
# Collections and other iterables
|
|
74
|
+
if isinstance(value, Iterable):
|
|
75
|
+
numbers = list(value)
|
|
76
|
+
results = [find_number(number) for number in numbers]
|
|
77
|
+
|
|
78
|
+
if isinstance(value, tuple):
|
|
79
|
+
return tuple(results)
|
|
80
|
+
|
|
81
|
+
return results
|
|
82
|
+
|
|
83
|
+
raise TypeError("Input must be an integer or an iterable of integers.")
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def trailing_zeros(*args):
|
|
5
|
-
"""
|
|
6
|
-
Count trailing zeros in the factorial of one or more non-negative integers.
|
|
7
|
-
|
|
8
|
-
Supports:
|
|
9
|
-
trailing_zeros(5) -> 1
|
|
10
|
-
trailing_zeros(10) -> 2
|
|
11
|
-
trailing_zeros([5, 10, 25]) -> [1, 2, 6]
|
|
12
|
-
trailing_zeros((5, 10, 25)) -> (1, 2, 6)
|
|
13
|
-
trailing_zeros(5, 10, 25) -> (1, 2, 6)
|
|
14
|
-
|
|
15
|
-
If no arguments are supplied, prompts the user for input.
|
|
16
|
-
|
|
17
|
-
Returns:
|
|
18
|
-
int: Trailing-zero count for one integer.
|
|
19
|
-
list: Results for a list or another iterable.
|
|
20
|
-
tuple: Results for a tuple or multiple positional integers.
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
def calculate(n):
|
|
24
|
-
if isinstance(n, bool) or not isinstance(n, int):
|
|
25
|
-
raise TypeError("Input must be an integer.")
|
|
26
|
-
|
|
27
|
-
if n < 0:
|
|
28
|
-
raise ValueError("Number must be non-negative.")
|
|
29
|
-
|
|
30
|
-
count = 0
|
|
31
|
-
|
|
32
|
-
while n > 0:
|
|
33
|
-
n //= 5
|
|
34
|
-
count += n
|
|
35
|
-
|
|
36
|
-
return count
|
|
37
|
-
|
|
38
|
-
# Interactive input
|
|
39
|
-
if not args:
|
|
40
|
-
n = int(input("Enter a non-negative integer: "))
|
|
41
|
-
return calculate(n)
|
|
42
|
-
|
|
43
|
-
# Multiple positional arguments
|
|
44
|
-
if len(args) > 1:
|
|
45
|
-
return tuple(calculate(n) for n in args)
|
|
46
|
-
|
|
47
|
-
value = args[0]
|
|
48
|
-
|
|
49
|
-
# Single integer
|
|
50
|
-
if isinstance(value, int) and not isinstance(value, bool):
|
|
51
|
-
return calculate(value)
|
|
52
|
-
|
|
53
|
-
# Reject strings and bytes
|
|
54
|
-
if isinstance(value, (str, bytes, bytearray)):
|
|
55
|
-
raise TypeError(
|
|
56
|
-
"Input must be an integer or an iterable of integers."
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
# Collection or iterable
|
|
60
|
-
if isinstance(value, Iterable):
|
|
61
|
-
numbers = list(value)
|
|
62
|
-
results = [calculate(n) for n in numbers]
|
|
63
|
-
|
|
64
|
-
if isinstance(value, tuple):
|
|
65
|
-
return tuple(results)
|
|
66
|
-
|
|
67
|
-
return results
|
|
68
|
-
|
|
69
|
-
raise TypeError(
|
|
70
|
-
"Input must be an integer or an iterable of integers."
|
|
71
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|