pythagix 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

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.
pythagix/__init__.py CHANGED
@@ -1,6 +1,6 @@
1
1
  # pythagix/__init__.py
2
2
  from .core import (
3
- prime_list,
3
+ filter_primes,
4
4
  is_prime,
5
5
  nth_prime,
6
6
  gcd,
pythagix/core.py CHANGED
@@ -1,144 +1,98 @@
1
- def filter_prime(number_list: list[int]) -> list[int]:
2
- """
3
- Returns a list of all prime numbers from a given list.
4
-
5
- Args:
6
- number_list (list[int]): The list of integers to check.
7
-
8
- Returns:
9
- list[int]: A list containing only the prime numbers from the input.
10
- """
11
- prime_number: list[int] = []
12
- for x in number_list:
13
- if x == 1:
14
- continue
15
- for y in range(2, int(x * 1 / 2 + 1)):
16
- if x % y == 0:
17
- break
18
- else:
19
- prime_number.append(x)
20
- return prime_number
21
-
22
-
23
- def is_prime(number: int) -> bool:
24
- """
25
- Checks whether a number is a prime number.
26
-
27
- Args:
28
- number (int): The number to check.
29
-
30
- Returns:
31
- bool: True if the number is prime, False otherwise.
32
- """
33
- for y in range(2, int(number * 1 / 2)):
34
- if number % y == 0:
35
- return False
36
- else:
1
+ from math import isqrt
2
+ from functools import reduce
3
+ from typing import List
4
+ import math
5
+
6
+ __all__ = [
7
+ "is_prime",
8
+ "filter_primes",
9
+ "nth_prime",
10
+ "gcd",
11
+ "is_perfect_square",
12
+ "count_factors",
13
+ "triangle_number",
14
+ ]
15
+
16
+
17
+ def is_prime(n: int) -> bool:
18
+ """Check if a number is prime."""
19
+ if n <= 1:
20
+ return False
21
+ if n == 2:
37
22
  return True
23
+ if n % 2 == 0:
24
+ return False
25
+ for i in range(3, isqrt(n) + 1, 2):
26
+ if n % i == 0:
27
+ return False
28
+ return True
38
29
 
39
30
 
40
- def nth_prime(index: int) -> int:
41
- """
42
- Returns the n-th prime number (1-indexed).
43
-
44
- Args:
45
- index (int): The position of the prime to find.
31
+ def filter_primes(numbers: List[int]) -> List[int]:
32
+ """Return only the prime numbers from the list."""
33
+ return [n for n in numbers if is_prime(n)]
46
34
 
47
- Returns:
48
- int: The n-th prime number.
49
35
 
50
- Raises:
51
- ValueError: If index is less than 1.
52
- """
53
- if index < 1:
36
+ def nth_prime(n: int) -> int:
37
+ """Return the n-th prime number (1-indexed)."""
38
+ if n < 1:
54
39
  raise ValueError("Index must be >= 1")
55
40
 
56
- count: int = 0
57
- prime_number: int = 2
41
+ count = 0
42
+ candidate = 2
58
43
  while True:
59
- if is_prime(prime_number):
44
+ if is_prime(candidate):
60
45
  count += 1
61
- if count == index:
62
- return prime_number
63
- prime_number += 1
64
-
65
-
66
- def gcd(number_list: list[int]) -> int:
67
- """
68
- Returns the greatest common divisor (GCD) of a list of integers.
69
-
70
- Args:
71
- number_list (list[int]): The list of integers.
72
-
73
- Returns:
74
- int: The greatest number that divides all elements in the list.
75
- """
76
- num: int = 2
77
- highest: int = 0
78
- while num <= min(number_list):
79
- for number in number_list:
80
- if number % num != 0:
81
- break
82
- else:
83
- highest = num
84
- num += 1
85
- return highest
86
-
87
-
88
- def is_perfect_square(number: int) -> bool:
89
- """
90
- Checks whether a number is a perfect square.
91
-
92
- Args:
93
- number (int): The number to check.
94
-
95
- Returns:
96
- bool: True if the number is a perfect square, False otherwise.
97
- """
98
- num: int = 0
99
- while num <= number:
100
- if num**2 == number:
101
- return True
102
- num += 1
103
- return False
104
-
105
-
106
- def count_factors(number: int) -> list[int]:
107
- """
108
- Returns a list of all factors (divisors) of a number.
109
-
110
- Args:
111
- number (int): The number to find factors of.
112
-
113
- Returns:
114
- list[int]: A list of all positive integers that divide the number evenly.
115
- """
116
- num: int = 1
117
- factors: list[int] = []
118
- while num <= number:
119
- if number % num == 0:
120
- factors.append(num)
121
- num += 1
122
- return factors
123
-
124
-
125
- def triangle_number(number: int) -> int:
126
- """
127
- Returns the n-th triangle number.
128
-
129
- Args:
130
- number (int): The term (n) of the triangle number sequence.
131
-
132
- Returns:
133
- int: The n-th triangle number, calculated as n(n+1)//2.
134
- """
135
- return number * (number + 1) // 2
46
+ if count == n:
47
+ return candidate
48
+ candidate += 1
49
+
50
+
51
+ def gcd(numbers: List[int]) -> int:
52
+ """Return the GCD of a list of numbers."""
53
+ if not numbers:
54
+ raise ValueError("List must not be empty")
55
+ return reduce(math.gcd, numbers)
56
+
57
+
58
+ def is_perfect_square(n: int) -> bool:
59
+ """Check if a number is a perfect square."""
60
+ if n < 0:
61
+ return False
62
+ root = isqrt(n)
63
+ return root * root == n
64
+
65
+
66
+ def count_factors(n: int) -> List[int]:
67
+ """Return all factors of a number."""
68
+ if n <= 0:
69
+ raise ValueError("Number must be positive")
70
+
71
+ factors = set()
72
+ for i in range(1, isqrt(n) + 1):
73
+ if n % i == 0:
74
+ factors.add(i)
75
+ factors.add(n // i)
76
+ return sorted(factors)
77
+
78
+
79
+ def triangle_number(n: int) -> int:
80
+ """Return the n-th triangle number."""
81
+ if n < 0:
82
+ raise ValueError("n must be >= 0")
83
+ return n * (n + 1) // 2
136
84
 
137
85
 
86
+ # Quick test zone
138
87
  if __name__ == "__main__":
139
88
 
140
89
  def main():
141
- """Runs a quick test of any function."""
142
- print(triangle_number(10))
90
+ """Function for testing other functions."""
91
+ print("Primes:", filter_primes([1, 2, 3, 4, 5, 16, 17, 19]))
92
+ print("5th Prime:", nth_prime(5))
93
+ print("GCD of [12, 18, 24]:", gcd([12, 18, 24]))
94
+ print("Is 49 perfect square?", is_perfect_square(49))
95
+ print("Factors of 28:", count_factors(28))
96
+ print("7th triangle number:", triangle_number(7))
143
97
 
144
98
  main()
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: pythagix
3
+ Version: 0.1.6
4
+ Summary: A mathy Python package with utilities like LCM, triangle numbers, etc.
5
+ Author: UltraQuantumScriptor
6
+ License: MIT
7
+ Keywords: math,prime,LCM,triangle numbers,gcd,utilities
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Requires-Python: >=3.6
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Dynamic: license-file
14
+ Dynamic: requires-python
15
+
16
+ Pythagix
17
+
18
+ Pythagix is a lightweight Python utility library for working with number theory.
19
+ It offers essential math functions like checking primes, computing triangle numbers, finding GCDs, and more — all in a fast, dependency-free package.
20
+
21
+ Installation
22
+
23
+ ```bash
24
+ pip install pythagix
25
+ ```
26
+ Features
27
+
28
+ is_prime(number) — Check if a number is prime
29
+
30
+ prime_list(numbers: list) — Return all prime numbers from a list
31
+
32
+ nth_prime(n) — Get the n-th prime number
33
+
34
+ gcd(numbers: list) — Compute the greatest common divisor of a list
35
+
36
+ is_perfect_square(n) — Check if a number is a perfect square
37
+
38
+ count_factors(n) — Count the total number of factors of a number
39
+
40
+ triangle_number(n) — Compute the n-th triangle number
41
+
42
+ Example Usage
43
+
44
+ ```python
45
+ from pythagix import is_prime, nth_prime, gcd, triangle_number
46
+
47
+ print(is_prime(13)) # True
48
+ print(nth_prime(10)) # 29
49
+ print(gcd([12, 18, 24])) # 6
50
+ print(triangle_number(7)) # 28
51
+ ```
52
+
53
+ About
54
+
55
+ Pythagix was built to give students, developers, and math enthusiasts a clean and simple way to explore number theory in Python.
56
+ It is ideal for learning, prototyping, or educational tools.
@@ -0,0 +1,7 @@
1
+ pythagix/__init__.py,sha256=6tpiGil3VFdLrZ9fUZ41YY7qAkNyWOC74fiUNCuXzAE,175
2
+ pythagix/core.py,sha256=RSL6W9NgMGRR3rVkPubpem7errcUFD5RrHF1mdTmDJ8,2425
3
+ pythagix-0.1.6.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
4
+ pythagix-0.1.6.dist-info/METADATA,sha256=GiOg5JBsM7Kv7vj1G7EDDUYcOe1PRNaIIj5F9f_W0Do,1659
5
+ pythagix-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ pythagix-0.1.6.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
7
+ pythagix-0.1.6.dist-info/RECORD,,
@@ -1,56 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: pythagix
3
- Version: 0.1.4
4
- Summary: A mathy Python package with utilities like LCM, triangle numbers, etc.
5
- Author: UltraQuantumScriptor
6
- License: MIT
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: License :: OSI Approved :: MIT License
9
- Requires-Python: >=3.6
10
- Description-Content-Type: text/markdown
11
- License-File: LICENSE
12
- Dynamic: license-file
13
- Dynamic: requires-python
14
-
15
- # 🧠 pythagix
16
-
17
- Math utilities for number nerds.
18
- Check primes, compute triangle numbers, find GCDs — all in one lightweight package.
19
- Because math shouldn't be a pain 🧮✨
20
-
21
- ---
22
-
23
- ## 📦 Installation
24
-
25
- ```bash
26
- pip install pythagix
27
- ```
28
-
29
- ⚙️ Features
30
-
31
- 🔢 is_prime(number) — Check if a number is prime
32
-
33
- 📜 prime_list([list]) — Return all primes in a list
34
-
35
- 🔎 nth_prime(n) — Get the n-th prime number
36
-
37
- 🤝 gcd([list]) — Greatest common divisor of a list
38
-
39
- 📏 is_perfect_square(n) — Check if n is a perfect square
40
-
41
- 🧱 count_factors(n) — Get all factors of a number
42
-
43
- 🔺 triangle_number(n) — Get the n-th triangle number
44
-
45
- 🧪 Examples
46
- ```python
47
- from pythagix import is_prime, nth_prime, gcd, triangle_number
48
-
49
- print(is_prime(13)) # True
50
- print(nth_prime(10)) # 29
51
- print(gcd([12, 18, 24])) # 6
52
- print(triangle_number(7)) # 28
53
- ```
54
-
55
- 📚 Why?
56
- pythagix was built to give math students, coders, and tinkerers a fast and fun way to explore number theory in Python. No heavy dependencies. Just pure mathy goodness.
@@ -1,7 +0,0 @@
1
- pythagix/__init__.py,sha256=A9cw-DpCoP2SUMlHar8PK0OAUSiFLQwoApZzx7oMslg,172
2
- pythagix/core.py,sha256=b5qw5ejc3-MsiNu4b4G6E-ILxaj8DyUI2tQwX1XP0bs,3395
3
- pythagix-0.1.4.dist-info/licenses/LICENSE,sha256=Qv2ilebwoUtMJnRsZwRy729xS5JZQzLauJ0tQzkAkTA,1088
4
- pythagix-0.1.4.dist-info/METADATA,sha256=THDZACzNVrTeErOXrlU8Z2aDg6_jsfDfwXV9lLljqbo,1513
5
- pythagix-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- pythagix-0.1.4.dist-info/top_level.txt,sha256=U3rm-YGObQkL0gSuVWFPZTakILlqyAd7pUVvtJiMlsE,9
7
- pythagix-0.1.4.dist-info/RECORD,,