Skip to content

Instantly share code, notes, and snippets.

charles gomes charles2588

Block or report user

Report or block charles2588

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Binary Search.py
#Binary Search
def binarysearch(arr,searchterm):
start=0 #we need start and end to calculate pivot
end=len(arr)-1
while(start<=end):#when to stop when start and end cross each other
pivot=int((start+end)/2)
if(arr[pivot])==searchterm:
return True
elif(arr[pivot]>searchterm):
end=pivot-1 #search left when pivot item is bigger
View UnkownArguments.py
#when you are not aware about number of arguments to a function
#args are passed in list
def multiplynumbers(*args):
count=1
for i in args:count*=i
return count
print(multiplynumbers(1,2,3,4,5))
#keyword arguments are passed as dict()
def addnumbers(**kwargs):
View Greedy_exceptIndexMutliplier.py
#Find product of all other numbers in the array for a given index except the number at that index.for ex. [1,2,3] = [6(3*2),3(1*3),2(1*2)]
def multiplier(arr):
result=[1 for i in arr]
#Brute force
for i in range(len(arr)):
for j in range(len(arr)):
if j==i:
continue
else:
result[i]=result[i]*arr[j]
View C93N-0.py
import random
def rand5():
return random.randrange(0,6,1)
def rand7():
diff=7-5
x=rand5()
if x<=rand5():
return x
else:
return x+diff
View C9dx-0.py
#Staircase builder
n=5
startforhash=n-1
str=""
for i in range(n):
for j in range(n):
if(j>=startforhash):
str+="#"
else:
str+=" "
View testnotebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.