jugaadcode 0.1.17__tar.gz → 0.1.18__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.17 → jugaadcode-0.1.18}/PKG-INFO +1 -1
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/pyproject.toml +1 -1
- jugaadcode-0.1.18/src/jugaadcode/armstrong.py +127 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode.egg-info/PKG-INFO +1 -1
- jugaadcode-0.1.17/src/jugaadcode/armstrong.py +0 -93
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/README.md +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/setup.cfg +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/__init__.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/anagram.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/binary_search.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/bubble_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/capitalize_words.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/character_frequency.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/climbing_stairs.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/coin_change.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/count_vowels.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/counting_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/duplicate_number.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/even_odd.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/factorial.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/factorial_trailing_zeros_direct.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/factorial_with_trailing_zeros.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/fibonacci.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/find_max.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/find_min.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/first_non_repeating.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/gcd.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/harshad_number.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/input_utils.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/insertion_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/kth_largest.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/lcm.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/linear_search.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/longest_consecutive.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/longest_word.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/matrix_transpose.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/maximum_subarray.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/merge_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/move_zeros.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/pair_with_difference.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/palindrome.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/perfect_number.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/power.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/prime.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/quick_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/remove_duplicates_array.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/remove_duplicates_string.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/reverse_linked_list.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/reverse_number.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/reverse_string.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/second_largest.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/selection_sort.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/strong_number.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/subsequence.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/sum_of_digits.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/trailing_zeros.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/two_sum.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/valid_parentheses.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode/word_count.py +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode.egg-info/SOURCES.txt +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode.egg-info/dependency_links.txt +0 -0
- {jugaadcode-0.1.17 → jugaadcode-0.1.18}/src/jugaadcode.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def is_armstrong(*args):
|
|
5
|
+
"""
|
|
6
|
+
Check whether one or more integers are Armstrong numbers.
|
|
7
|
+
|
|
8
|
+
Supports:
|
|
9
|
+
is_armstrong(153)
|
|
10
|
+
is_armstrong(153, 370, 123)
|
|
11
|
+
is_armstrong([153, 370, 123])
|
|
12
|
+
is_armstrong((153, 370, 123))
|
|
13
|
+
is_armstrong({153, 370, 123})
|
|
14
|
+
is_armstrong(range(100, 200))
|
|
15
|
+
is_armstrong(n for n in [153, 370, 123])
|
|
16
|
+
is_armstrong()
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
bool
|
|
21
|
+
For a single integer.
|
|
22
|
+
|
|
23
|
+
list[bool]
|
|
24
|
+
For lists, sets, ranges, generators, and other iterables.
|
|
25
|
+
|
|
26
|
+
tuple[bool, ...]
|
|
27
|
+
For tuples or multiple positional arguments.
|
|
28
|
+
|
|
29
|
+
Raises
|
|
30
|
+
------
|
|
31
|
+
TypeError
|
|
32
|
+
If an input is not an integer or supported iterable.
|
|
33
|
+
|
|
34
|
+
ValueError
|
|
35
|
+
If an input contains a negative integer or no values.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
# Interactive input when no arguments are provided.
|
|
39
|
+
if not args:
|
|
40
|
+
value = input(
|
|
41
|
+
"Enter number(s) to check, separated by commas: "
|
|
42
|
+
).strip()
|
|
43
|
+
|
|
44
|
+
if not value:
|
|
45
|
+
raise ValueError("Input cannot be empty.")
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
args = tuple(
|
|
49
|
+
int(item.strip()) for item in value.split(",")
|
|
50
|
+
)
|
|
51
|
+
except ValueError as exc:
|
|
52
|
+
raise ValueError(
|
|
53
|
+
"Enter valid integers separated by commas."
|
|
54
|
+
) from exc
|
|
55
|
+
|
|
56
|
+
# Determine the input format.
|
|
57
|
+
if len(args) > 1:
|
|
58
|
+
# Multiple positional arguments.
|
|
59
|
+
numbers = list(args)
|
|
60
|
+
input_type = "tuple"
|
|
61
|
+
|
|
62
|
+
else:
|
|
63
|
+
value = args[0]
|
|
64
|
+
|
|
65
|
+
if isinstance(value, bool):
|
|
66
|
+
numbers = [value]
|
|
67
|
+
input_type = "single"
|
|
68
|
+
|
|
69
|
+
elif isinstance(value, int):
|
|
70
|
+
numbers = [value]
|
|
71
|
+
input_type = "single"
|
|
72
|
+
|
|
73
|
+
elif isinstance(value, (str, bytes, bytearray)):
|
|
74
|
+
raise TypeError(
|
|
75
|
+
"Input must contain integers, not strings or bytes."
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
elif isinstance(value, Iterable):
|
|
79
|
+
numbers = list(value)
|
|
80
|
+
|
|
81
|
+
if isinstance(value, tuple):
|
|
82
|
+
input_type = "tuple"
|
|
83
|
+
else:
|
|
84
|
+
input_type = "list"
|
|
85
|
+
|
|
86
|
+
else:
|
|
87
|
+
raise TypeError(
|
|
88
|
+
"Input must be an integer or an iterable of integers."
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Reject empty collections and generators.
|
|
92
|
+
if not numbers:
|
|
93
|
+
raise ValueError("At least one number must be provided.")
|
|
94
|
+
|
|
95
|
+
def check_number(n):
|
|
96
|
+
# Booleans are not accepted as integers.
|
|
97
|
+
if isinstance(n, bool) or not isinstance(n, int):
|
|
98
|
+
raise TypeError("Every value must be an integer.")
|
|
99
|
+
|
|
100
|
+
if n < 0:
|
|
101
|
+
raise ValueError(
|
|
102
|
+
"Armstrong number checking requires "
|
|
103
|
+
"non-negative integers."
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
digits = str(n)
|
|
107
|
+
power = len(digits)
|
|
108
|
+
|
|
109
|
+
total = sum(
|
|
110
|
+
int(digit) ** power for digit in digits
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
return total == n
|
|
114
|
+
|
|
115
|
+
# Calculate results.
|
|
116
|
+
results = [
|
|
117
|
+
check_number(n) for n in numbers
|
|
118
|
+
]
|
|
119
|
+
|
|
120
|
+
# Return the result in the appropriate format.
|
|
121
|
+
if input_type == "single":
|
|
122
|
+
return results[0]
|
|
123
|
+
|
|
124
|
+
if input_type == "tuple":
|
|
125
|
+
return tuple(results)
|
|
126
|
+
|
|
127
|
+
return results
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
def is_armstrong(*args):
|
|
2
|
-
"""
|
|
3
|
-
Check whether one or more integers are Armstrong numbers.
|
|
4
|
-
|
|
5
|
-
Supports:
|
|
6
|
-
is_armstrong(153)
|
|
7
|
-
is_armstrong(153, 370, 123)
|
|
8
|
-
is_armstrong([153, 370, 123])
|
|
9
|
-
is_armstrong((153, 370, 123))
|
|
10
|
-
is_armstrong({153, 370, 123})
|
|
11
|
-
is_armstrong(range(100, 200))
|
|
12
|
-
is_armstrong()
|
|
13
|
-
|
|
14
|
-
Returns
|
|
15
|
-
-------
|
|
16
|
-
bool
|
|
17
|
-
For a single integer.
|
|
18
|
-
list[bool] or tuple[bool, ...] or set[bool]
|
|
19
|
-
For multiple integers, according to the input format.
|
|
20
|
-
|
|
21
|
-
Raises
|
|
22
|
-
------
|
|
23
|
-
TypeError
|
|
24
|
-
If an input is not an integer or supported collection.
|
|
25
|
-
ValueError
|
|
26
|
-
If an input contains a negative integer or no values.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
if not args:
|
|
30
|
-
value = input(
|
|
31
|
-
"Enter number(s) to check, separated by commas: "
|
|
32
|
-
).strip()
|
|
33
|
-
|
|
34
|
-
if not value:
|
|
35
|
-
raise ValueError("Input cannot be empty.")
|
|
36
|
-
|
|
37
|
-
try:
|
|
38
|
-
args = tuple(int(item.strip()) for item in value.split(","))
|
|
39
|
-
except ValueError as exc:
|
|
40
|
-
raise ValueError(
|
|
41
|
-
"Enter valid integers separated by commas."
|
|
42
|
-
) from exc
|
|
43
|
-
|
|
44
|
-
# Determine whether the caller supplied a collection or
|
|
45
|
-
# multiple individual arguments.
|
|
46
|
-
if len(args) == 1:
|
|
47
|
-
value = args[0]
|
|
48
|
-
|
|
49
|
-
if isinstance(value, (list, tuple, set, range)):
|
|
50
|
-
numbers = list(value)
|
|
51
|
-
input_type = type(value)
|
|
52
|
-
else:
|
|
53
|
-
numbers = [value]
|
|
54
|
-
input_type = None
|
|
55
|
-
else:
|
|
56
|
-
numbers = list(args)
|
|
57
|
-
input_type = tuple
|
|
58
|
-
|
|
59
|
-
if not numbers:
|
|
60
|
-
raise ValueError("At least one number must be provided.")
|
|
61
|
-
|
|
62
|
-
def check_number(n):
|
|
63
|
-
if isinstance(n, bool) or not isinstance(n, int):
|
|
64
|
-
raise TypeError("Every value must be an integer.")
|
|
65
|
-
|
|
66
|
-
if n < 0:
|
|
67
|
-
raise ValueError(
|
|
68
|
-
"Armstrong number checking requires non-negative integers."
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
digits = str(n)
|
|
72
|
-
power = len(digits)
|
|
73
|
-
|
|
74
|
-
total = sum(int(digit) ** power for digit in digits)
|
|
75
|
-
|
|
76
|
-
return total == n
|
|
77
|
-
|
|
78
|
-
results = [check_number(n) for n in numbers]
|
|
79
|
-
|
|
80
|
-
# Preserve a single result for a single integer.
|
|
81
|
-
if input_type is None:
|
|
82
|
-
return results[0]
|
|
83
|
-
|
|
84
|
-
if input_type is list or input_type is range:
|
|
85
|
-
return results
|
|
86
|
-
|
|
87
|
-
if input_type is tuple:
|
|
88
|
-
return tuple(results)
|
|
89
|
-
|
|
90
|
-
if input_type is set:
|
|
91
|
-
return set(results)
|
|
92
|
-
|
|
93
|
-
return results
|
|
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
|
|
File without changes
|