dolphinmath 0.0.1__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.
- DolphinMath/__init__.py +16 -0
- DolphinMath/numbers.py +37 -0
- DolphinMath/prime.py +45 -0
- DolphinMath/sequences.py +12 -0
- DolphinMath/series.py +16 -0
- DolphinMath/stats.py +20 -0
- dolphinmath-0.0.1.dist-info/METADATA +20 -0
- dolphinmath-0.0.1.dist-info/RECORD +10 -0
- dolphinmath-0.0.1.dist-info/WHEEL +5 -0
- dolphinmath-0.0.1.dist-info/top_level.txt +1 -0
DolphinMath/__init__.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
owner = "PEDDAKOTLA KARTHIKEYA"
|
|
2
|
+
version="0.0.1"
|
|
3
|
+
|
|
4
|
+
from .prime import (
|
|
5
|
+
is_prime,
|
|
6
|
+
list_primes,
|
|
7
|
+
primes,
|
|
8
|
+
count_primes,
|
|
9
|
+
nth_prime,
|
|
10
|
+
next_prime,
|
|
11
|
+
)
|
|
12
|
+
from .numbers import *
|
|
13
|
+
from .sequences import *
|
|
14
|
+
from .prime import *
|
|
15
|
+
from .stats import *
|
|
16
|
+
from .series import *
|
DolphinMath/numbers.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
def gcd(a, b):
|
|
2
|
+
while b != 0:
|
|
3
|
+
a, b = b, a % b
|
|
4
|
+
return a
|
|
5
|
+
|
|
6
|
+
def hcf(a, b):
|
|
7
|
+
return gcd(a, b)
|
|
8
|
+
|
|
9
|
+
def lcm(a, b):
|
|
10
|
+
return abs(a * b) // gcd(a, b)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def prime_factors(n):
|
|
14
|
+
factors = []
|
|
15
|
+
d = 2
|
|
16
|
+
while d * d <= n:
|
|
17
|
+
while n % d == 0:
|
|
18
|
+
factors.append(d)
|
|
19
|
+
n //= d
|
|
20
|
+
d += 1
|
|
21
|
+
if n > 1:
|
|
22
|
+
factors.append(n)
|
|
23
|
+
return factors
|
|
24
|
+
|
|
25
|
+
def factors(n):
|
|
26
|
+
return [i for i in range(1, n + 1) if n % i == 0]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def is_perfect(n):
|
|
30
|
+
return sum(factors(n)) - n == n
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def is_armstrong(n):
|
|
34
|
+
s = str(n)
|
|
35
|
+
power = len(s)
|
|
36
|
+
total = sum(int(d) ** power for d in s)
|
|
37
|
+
return total == n
|
DolphinMath/prime.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from math import sqrt
|
|
2
|
+
def primes(a,b):
|
|
3
|
+
for i in range(a,b+1):
|
|
4
|
+
if i<2:
|
|
5
|
+
continue
|
|
6
|
+
for j in range(2,int(sqrt(i))+1):
|
|
7
|
+
if i%j==0:
|
|
8
|
+
break
|
|
9
|
+
else:
|
|
10
|
+
print(f"{i}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def is_prime(n):
|
|
14
|
+
if n < 2:
|
|
15
|
+
return False
|
|
16
|
+
for i in range(2, int(sqrt(n)) + 1):
|
|
17
|
+
if n % i == 0:
|
|
18
|
+
return False
|
|
19
|
+
return True
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def list_primes(a, b):
|
|
23
|
+
return [i for i in range(a, b + 1) if is_prime(i)]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def count_primes(a, b):
|
|
27
|
+
return len(list_primes(a, b))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def nth_prime(n):
|
|
31
|
+
count = 0
|
|
32
|
+
num = 2
|
|
33
|
+
while True:
|
|
34
|
+
if is_prime(num):
|
|
35
|
+
count += 1
|
|
36
|
+
if count == n:
|
|
37
|
+
return num
|
|
38
|
+
num += 1
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def next_prime(n):
|
|
42
|
+
num = n + 1
|
|
43
|
+
while not is_prime(num):
|
|
44
|
+
num += 1
|
|
45
|
+
return num
|
DolphinMath/sequences.py
ADDED
DolphinMath/series.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
def ap_nth(a, d, n):
|
|
2
|
+
return a + (n - 1) * d
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def ap_sum(a, d, n):
|
|
6
|
+
return n / 2 * (2 * a + (n - 1) * d)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def gp_nth(a, r, n):
|
|
10
|
+
return a * (r ** (n - 1))
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def gp_sum(a, r, n):
|
|
14
|
+
if r == 1:
|
|
15
|
+
return a * n
|
|
16
|
+
return a * (r**n - 1) / (r - 1)
|
DolphinMath/stats.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
def mean(nums):
|
|
2
|
+
return sum(nums) / len(nums)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def median(nums):
|
|
6
|
+
nums = sorted(nums)
|
|
7
|
+
n = len(nums)
|
|
8
|
+
mid = n // 2
|
|
9
|
+
|
|
10
|
+
if n % 2 == 0:
|
|
11
|
+
return (nums[mid - 1] + nums[mid]) / 2
|
|
12
|
+
return nums[mid]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def mode(nums):
|
|
16
|
+
freq = {}
|
|
17
|
+
for n in nums:
|
|
18
|
+
freq[n] = freq.get(n, 0) + 1
|
|
19
|
+
highest = max(freq.values())
|
|
20
|
+
return [k for k, v in freq.items() if v == highest]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dolphinmath
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Simple math helper library made by a student
|
|
5
|
+
Author: Peddakotla Karthikeya
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://pypi.org/project/dolphinmath/
|
|
8
|
+
Requires-Python: >=3.8
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
|
|
11
|
+
# dolphinmath
|
|
12
|
+
|
|
13
|
+
A simple math library created by a student.
|
|
14
|
+
|
|
15
|
+
### Example
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from dolphinmath.prime import primes
|
|
19
|
+
|
|
20
|
+
primes(1, 20)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
DolphinMath/__init__.py,sha256=_0wndCnEoADu75pysmQ3TyeGQGq-igIhKAcVs_dNgL8,292
|
|
2
|
+
DolphinMath/numbers.py,sha256=J9l_mVupn-miz4Dh11StZ253ON4_mcjCm8zBBq1vV2Q,669
|
|
3
|
+
DolphinMath/prime.py,sha256=4LlMQOsfr8lhcp-wLHDX-xhOn2njO8C_hKXS2AZK0JQ,854
|
|
4
|
+
DolphinMath/sequences.py,sha256=KZ5j54ujqbs0pO5Ln7uloZh17GhKle5BwDzDmwCT2xg,231
|
|
5
|
+
DolphinMath/series.py,sha256=GPKQHmcEmlD6uGh5fyWIr5gmcNHVfT7Zi8hLOn9jjdE,276
|
|
6
|
+
DolphinMath/stats.py,sha256=mZCnZj1XEyzG4UVtNVxw4J6kZ9YiegDTs0hGdOcBnjw,413
|
|
7
|
+
dolphinmath-0.0.1.dist-info/METADATA,sha256=vTeFqUuoZZMw029a0tPnlG_BugUz0HavboUdQqBbG4M,432
|
|
8
|
+
dolphinmath-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
dolphinmath-0.0.1.dist-info/top_level.txt,sha256=JFtuifHpaiQVJnujzHl1U_lBbnSN7ZJVzixIHx6Bh-k,12
|
|
10
|
+
dolphinmath-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
DolphinMath
|