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
import time | |
def function_1(*parameters): | |
#do something | |
# return value | |
def function_2(*parameters): | |
#do something | |
#return value | |
#measuring time taken by function_1 | |
start_of_f1 = time.time() |
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
import time | |
start_time = time.time() | |
""" | |
Some Code | |
""" | |
end_time = time.time() | |
print(f"The execution time is: {end_time-start_time}") |
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
def bubble_sort(arr): | |
for i in range(len(arr)): | |
for j in range(0, len(arr) - i - 1): | |
if arr[j] > arr[j + 1]: | |
arr[j], arr[j + 1] = arr[j + 1], arr[j] | |
return arr | |
def make_random_array(): | |
from random import randint |
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
import timeit | |
#This code will be executed only once, before stmt. | |
setup_code = "from math import sqrt" | |
#This code will be executed as specified by the parameter 'number' | |
stmt_code = "sum(sqrt(x) for x in range(1,10000))" | |
iterations = 10000 | |
time = timeit.timeit(stmt = stmt_code, setup = setup_code, number = iterations) |
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
def MiniStringFuck_interpreter(code): | |
memory = 0 #initialize the memory cell value at zero | |
output="" #output string | |
for char in code: | |
if char=="+": | |
memory+=1 | |
if memory>255: | |
memory=memory%256 | |
if char==".": | |
output+=chr(memory) |
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
MiniStringFuck_interpreter(+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.+.) | |
#>> Prints all the uppercase English Alphabets. |
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
import time | |
import sys | |
a=time.time() | |
def same(n): | |
return sorted(str(n))==sorted(str(2*n)) ==\ | |
sorted(str(3*n))==sorted(str(4*n))==sorted(str(5*n)) | |
""" | |
Here I have tried to optimize the performance by chekcing only the numbers from n to 2n |
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
""" | |
Problem 37 on project Euler | |
https://projecteuler.net/problem=37 | |
""" | |
""" | |
Note: This code takes about 2 seconds to execute. You ca reduce this time by adapting to | |
faster methods of checking if a number is prime or not like the Seive method. | |
But this code is intended to be beginner friendly so I have used the simple way to check for primes. | |
""" |
NewerOlder