View odds
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 sort_array(arr): | |
oddarr=[] | |
for i in arr: | |
if(i%2!=0): | |
oddarr.append(i) | |
oddarr=sorted(oddarr) | |
j=0 |
View determinant
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 numpy as np | |
def determinant(matrix): | |
return round(np.linalg.det(matrix),3) |
View calculator
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
class Calculator(object): | |
def evaluate(self, string): | |
return round(eval(string), 10) |
View ip validation
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 is_valid_IP(string): | |
if(string==""): | |
return False | |
string=string.split('.') | |
count = 0 | |
for i in string: | |
if(i[0]=="0" and len(i)!=1): | |
return False | |
elif(i.isdigit()==False): | |
return False |
View palindrome chain length
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 check_palindrome(a): | |
return str(a) == str(a)[::-1] | |
def palindrome_chain_length(n): | |
steps=0 | |
while(check_palindrome(n)!=True): | |
n=n+int(str(n)[::-1]) | |
steps+=1 | |
return steps |
View friend cheating
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 removNb(n): | |
result=[] | |
for a in range(1,n+1): | |
for b in range(1,n+1): | |
if(a*b==(n*(n+1)/2-a-b)): | |
result.append((a,b)) | |
return result |
View trailing zeros
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 zeros(x): | |
i = 5 | |
count = 0 | |
while x >= i: | |
count += x // i | |
i *= 5 | |
return count |
View first non-repeating character
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 first_non_repeating_letter(string): | |
for i in string: | |
if(string.lower().count(i.lower())==1): | |
return i | |
return "" |
View scramblies
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 collections import Counter | |
def scramble(s1, s2): | |
letters = Counter(s1) | |
word = Counter(s2) | |
diff = word - letters | |
return len(diff) == 0 |