Instantly share code, notes, and snippets.

🤔
<Comprehending>

Kushagra Bansal Kush1101

🤔
<Comprehending>
Created May 18, 2020 12:10
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. """
Created May 21, 2020 08:45
Project Euler Problem 52 solution @ https://projecteuler.net/problem=52
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
Last active August 2, 2020 18:05
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.
Last active August 2, 2020 17:50
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)
Created September 1, 2020 06:40
Medium_timeit
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)
Last active September 1, 2020 07:21
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
Created September 1, 2020 08:33
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}")
Created September 1, 2020 08:37
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()
Created September 24, 2020 12:55
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
 from itertools import count for i in count(0,2): print(i, end = " ") if i==20: break # OUTPUT ''' 0 2 4 6 8 10 12 14 16 18 20 '''
Created September 24, 2020 13:03
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
 from itertools import count count_floating_negative = count(start=0.5, step = -0.5) print(list(next(count_floating_negative) for _ in range(10))) # OUTPUT ''' [0.5, 0.0, -0.5, -1.0, -1.5, -2.0, -2.5, -3.0, -3.5, -4.0] '''