-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**/*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import time | ||
from numba import jit | ||
|
||
NUMBER = 500000 | ||
|
||
@jit(nopython=True) | ||
def collatz(x): | ||
len = 0 | ||
while x > 1: | ||
if x % 2 == 0: | ||
x = x // 2 | ||
else: | ||
x = 3 * x + 1 | ||
len += 1 | ||
return len | ||
|
||
@jit(nopython=True) | ||
def findMaxCollatz(to): | ||
result = (1, 1) | ||
for number in range(1, to + 1): | ||
len = collatz(number) | ||
if len > result[1]: | ||
result = (number, len) | ||
return result | ||
|
||
if __name__ == "__main__": | ||
startTimeMs = int(round(time.time() * 1000)) | ||
|
||
result = findMaxCollatz(NUMBER) | ||
print(result) | ||
|
||
endTimeMs = int(round(time.time() * 1000)) | ||
executionTime = endTimeMs - startTimeMs | ||
|
||
print(f"Execution time: {executionTime}ms") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import time | ||
from numba import jit | ||
|
||
def index(): | ||
for y in range(-39, 39): | ||
print() | ||
for x in range(-39, 39): | ||
i = mandelbrot(x / 40.0, y / 40.0) | ||
|
||
if i == 0: | ||
print("*", end="") | ||
else: | ||
print(" ", end="") | ||
|
||
|
||
@jit(nopython=True) | ||
def mandelbrot(x, y): | ||
cr = y - 0.5 | ||
ci = x | ||
zi = 0.0 | ||
zr = 0.0 | ||
i = 0 | ||
|
||
while True: | ||
i += 1 | ||
|
||
temp = zr * zi | ||
|
||
zr2 = zr ** 2 | ||
zi2 = zi ** 2 | ||
|
||
zr = zr2 - zi2 + cr | ||
zi = 2 * temp + ci | ||
|
||
if zi2 + zr2 > 16: | ||
return i | ||
|
||
if i > 5000: | ||
return 0 | ||
|
||
if __name__ == "__main__": | ||
startTimeMs = int(round(time.time() * 1000)) | ||
|
||
index() | ||
|
||
endTimeMs = int(round(time.time() * 1000)) | ||
executionTime = endTimeMs - startTimeMs | ||
|
||
print(f"Execution time: {executionTime}ms") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import time | ||
from math import sqrt | ||
import numba | ||
|
||
limit = 500000 | ||
|
||
@numba.jit(nopython=True) | ||
def get_last_prime(count): | ||
last_prime = 2 | ||
|
||
# Traverse each number from 1 to N with the help of for loop | ||
for num in range(3, count, 2): | ||
is_prime = True | ||
limit = int(sqrt(num)) | ||
|
||
for i in range(3, limit, 2): | ||
if num % i == 0: | ||
is_prime = False | ||
break | ||
|
||
if is_prime: | ||
last_prime = num | ||
|
||
return last_prime | ||
|
||
if __name__ == "__main__": | ||
start_time_ms = int(round(time.time() * 1000)) | ||
|
||
last_prime = get_last_prime(limit) | ||
print(f"Last prime: {last_prime}") | ||
|
||
end_time_ms = int(round(time.time() * 1000)) | ||
execution_time = end_time_ms - start_time_ms | ||
print(f"Execution time: {execution_time}ms") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import time | ||
from numba import jit | ||
|
||
@jit(nopython=True) | ||
def tak(x, y, z): | ||
if (y < x): | ||
return tak(tak(x - 1, y, z), tak(y - 1, z, x), tak(z - 1, x, y)) | ||
else: | ||
return z | ||
|
||
startTimeMs = int(round(time.time() * 1000)) | ||
|
||
print(tak(30, 22, 12)) | ||
|
||
endTimeMs = int(round(time.time() * 1000)) | ||
executionTime = endTimeMs - startTimeMs | ||
print(f"Execution time: {executionTime}ms") |