blob_id stringlengths 40 40 | repo_name stringlengths 5 127 | path stringlengths 2 523 | length_bytes int64 22 3.06M | score float64 3.5 5.34 | int_score int64 4 5 | text stringlengths 22 3.06M |
|---|---|---|---|---|---|---|
d29606d382e68690e5d3f2a033619f6b29052f65 | daniel-reich/ubiquitous-fiesta | /CHwX2o6rqrBsL4gzr_14.py | 138 | 3.625 | 4 |
def check_title(txt):
txt = txt.split(" ")
for i in range(len(txt)):
if txt[i][0].islower():
return False;
return True;
|
207184b5f0ac2d5971b6da276bad454de0caa825 | daniel-reich/ubiquitous-fiesta | /tbz5ji3ocwzAeLQNa_24.py | 510 | 3.703125 | 4 |
def exit_maze(maze, directions):
pos=[0,0]
for i in range(len(maze)):
for j in range(len(maze[i])):
if maze[i][j]==2:
pos[0]+=i
pos[1]+=j
for k in directions:
if k=='N': pos[0]-=1
if k=='E': pos[1]+=1
if k=='S': pos[0]+=1
if k=='W': pos[1]-=1
if pos[0]<0 or pos[0]>9 or pos[1]<0 or pos[1]>9 or maze[pos[0]][pos[1]]==1:
return 'Dead'
if maze[pos[0]][pos[1]]==3:return 'Finish'
return 'Lost'
|
6e10d9b482990da0e2f164bdbe0a82d6fd6898a8 | daniel-reich/ubiquitous-fiesta | /FLgJEC8SK2AJYLC6y_6.py | 245 | 3.5625 | 4 |
def possible_path(lst):
for cur,fut in zip(lst,lst[1:]):
if cur=='H' and fut in (1,3) or cur in (1,3) and fut=='H':
return False
if isinstance(cur,int) and isinstance(fut,int) and cur%2==fut%2:
return False
return True
|
f360db4740386c97aba6f6e32981c549e02f6660 | daniel-reich/ubiquitous-fiesta | /F7iLaLDBHqshWSZz5_15.py | 117 | 3.5 | 4 |
def to_float_list(lst):
result = []
for i in range(len(lst)):
result.append(float(lst[i]))
return result
|
1d19b07c31e1e0fa72990b43a6e645f4c18c3f06 | daniel-reich/ubiquitous-fiesta | /QB6kPXQkFgMkzcc2h_0.py | 114 | 3.8125 | 4 |
def remove_abc(txt):
res = ''.join(i for i in txt if i not in 'abc')
return None if res == txt else res
|
a93d6d3cc344da7527559fd3a4101d0d46cedd5b | daniel-reich/ubiquitous-fiesta | /oTzuXDWL26gnY5a5P_11.py | 242 | 3.703125 | 4 |
def prime_numbers(num):
count=0
for i in range(2,num+1):
if prime(i):
count+=1
return count
def prime(n):
if n == 2:
return True
else:
for i in range(2,n):
if n%i == 0:
return False
return True
|
538a7a8b61b7fb3065b2ec31d01d2e84af1c2c04 | daniel-reich/ubiquitous-fiesta | /6vSZmN66xhMRDX8YT_5.py | 156 | 3.5 | 4 |
def advanced_sort(lst):
out, seen = [], []
for x in lst:
if x not in seen:
out.append([x] * lst.count(x))
seen.append(x)
return out
|
9956321cc5f8f5ee5b52e26e996f45b5b8daaefa | daniel-reich/ubiquitous-fiesta | /cEzT2e8tLpwYnrstP_13.py | 225 | 3.609375 | 4 |
def swap_d(k, v, swapped):
final_dct = {}
if swapped is False:
for i in range(len(k)):
final_dct.update({k[i]:v[i]})
else:
for i in range(len(k)):
final_dct.update({v[i]:k[i]})
return final_dct
|
5d1840611e02dbebaf12bfe2ccc2811b634b241f | daniel-reich/ubiquitous-fiesta | /6pjjWy5ST2eMKtGkh_10.py | 281 | 3.71875 | 4 |
def replace(txt, r):
result = ''
first, last = r.split('-')
for num in range(ord(first), ord(last)+1):
result += chr(num)
sol = ''
for char in txt:
if char in result:
sol += '#'
else:
sol += char
return sol
|
25ed4d781fc857cd4a2fa4a48d43421ac716a9cb | daniel-reich/ubiquitous-fiesta | /LyzKTyYdKF4oDf5bG_1.py | 598 | 3.84375 | 4 |
def find_longest(s):
n_letters = []
longest_word = ''
for i in s.split():
n_letters.append(len(i))
for j in s.split():
if len(j) == max(n_letters):
longest_word = j
if "." in longest_word:
longest_word = longest_word[:-1]
elif "!" in longest_word:
longest_word = longest_word[:-1]
elif "'s" in longest_word:
longest_word = longest_word[:-2]
if '\"' in longest_word:
longest_word = longest_word[1:-1]
return longest_word.lower()
|
609962a90ab42709aa1acc436e344931a94c0229 | daniel-reich/ubiquitous-fiesta | /i5kcGmT7gFKkf3mTi_20.py | 232 | 3.890625 | 4 |
def data_type(value):
a=str(type(value))
if a[8:-2]=="dict":return "dictionary"
if a[8:-2]=="str":return "string"
if a[8:-2]=="int":return "integer"
if a[8:-2]=="datetime.date":return "date"
return a[8:-2]
|
6e3c2d6facb598d431869ae9d29cf99a4a9247fd | daniel-reich/ubiquitous-fiesta | /xWW8PMuLN8hmAgLMJ_3.py | 482 | 3.703125 | 4 |
def postfix(expression):
stack = expression.split(" ")[::-1];
operations ="+-*/";
result_stack = [];
while(len(stack) != 0):
current = stack.pop();
if (current in operations):
a,b = result_stack.pop() , result_stack.pop()
result = eval(b+ current + a);
result_stack.append(str(result));
elif (current.isdigit()) :
result_stack.append(current)
else :
return "unknown provided value anyway";
return float(result_stack[0]);
|
56f5177a1b439d924733ff53414b176e630e23c2 | daniel-reich/ubiquitous-fiesta | /JcmSuBX2EaPfRkqZ8_12.py | 173 | 3.6875 | 4 |
def get_total_price(groceries):
total = 0
for eachfood in groceries:
x = eachfood['quantity']
y = eachfood['price'] * x
total += y
return round(total,1)
|
5825cdd70b51bb4b417cdfac69ca7117f7c80e2c | daniel-reich/ubiquitous-fiesta | /RoEn338P4xAf7mNNg_10.py | 418 | 3.75 | 4 |
def shortest_path(lst):
vertical, horizontal = 0, 0
coords = []
for r in range(len(lst)):
for c in range(len(lst[0])):
if lst[r][c] != '0':
coords.append((lst[r][c], r, c))
coords.sort()
for (_, r1, c1), (_, r2, c2) in zip(coords, coords[1:]):
vertical += abs(r1 - r2)
horizontal += abs(c1 - c2)
return vertical + horizontal
|
41a74de85559448f4ed2d1c1e71ddf5a09ccba1e | daniel-reich/ubiquitous-fiesta | /xmyNqzxAgpE47zXEt_13.py | 358 | 4.09375 | 4 |
def is_alphabetically_sorted(txt):
import string
txt_clean = txt.translate(str.maketrans('', '', string.punctuation)).split(" ")
sorted_txt = ["".join(sorted(txt_clean[i])) for i in range(0,len(txt_clean))]
txt_compare = [sorted_txt[i] == txt_clean[i] and len(txt_clean[i])>=3 for i in range(0,len(sorted_txt))]
return any(txt_compare)
|
e48d9222600d3001e7122f2b182664b6127710be | daniel-reich/ubiquitous-fiesta | /ik9CtowAndmAiStze_6.py | 157 | 3.546875 | 4 |
from collections import Counter as C
def frequency_sort(s):
A=[x*C(s)[x] for x in C(s)]
A=sorted(A, key=lambda x: (-len(x), x[0]))
return ''.join(A)
|
e1fa60c6139bb560014225b50106284844e58331 | daniel-reich/ubiquitous-fiesta | /F3M4PhqC4JdX28Qmx_4.py | 434 | 3.703125 | 4 |
def back_to_home(directions):
countN = 0
countS = 0
countE = 0
countW = 0
for let in directions:
if let == 'N':
countN = countN + 1
if let == 'S':
countS = countS + 1
if let == 'E':
countE = countE + 1
if let == 'W':
countW = countW + 1
if countN == countS and countE == countW:
return True
else:
return False
|
d0dec682c42d731df3d371c9640f37b175843a79 | daniel-reich/ubiquitous-fiesta | /9Px2rkc9TPhK54wDb_4.py | 261 | 3.5 | 4 |
def ecg_seq_index(n):
seq = [1, 2]
while n not in seq:
i = min(seq)
while i in seq or all(f not in fact(seq[-1]) for f in fact(i)):
i += 1
seq += [i]
return len(seq) - 1
def fact(n):
return [i for i in range(2, n+1) if not n % i]
|
b9078e5718d051c34ae84a4cb4ba286765410078 | daniel-reich/ubiquitous-fiesta | /Mkt3yqQMsw9e3Jmjq_12.py | 639 | 3.5625 | 4 |
from itertools import dropwhile
def disjoint_cycle_form(perm):
cycle = []
right_place = lambda x: perm.index(x) == sorted(perm).index(x)
while True:
perm = list(dropwhile(lambda x: right_place(x),perm))
if not perm:
return set(cycle)
cycle.append([min(perm),perm[0]])
index = perm.index(min(perm))
perm[index] = perm[0]
perm.pop(0)
index -= 1
while True:
if sorted(perm)[index] == perm[index]:
cycle[-1] = tuple(cycle[-1])
break
index2 = sorted(perm).index(perm[index])
cycle[-1].append(perm[index2])
perm[index],perm[index2] = perm[index2],perm[index]
|
01555a60459c9b1f5185109fde82482e5e52aef6 | daniel-reich/ubiquitous-fiesta | /GJcGhBinX2hr5Wq6m_4.py | 179 | 3.65625 | 4 |
def move_zeros(lst):
lst1=[]
lst2=[]
lst3=[]
for i in lst:
if i!=0 or i is False:
lst1.append(i)
else:
lst2.append(i)
lst3=lst1+lst2
return lst3
|
515d0f373684b791e44c2ec1ec6dc7c587174567 | daniel-reich/ubiquitous-fiesta | /nC7iHBbN8FEPy2EJ2_17.py | 231 | 3.515625 | 4 |
import math
class Circle:
def __init__(self, radius = 0):
self.radius = radius
def getArea(self):
return math.pi * self.radius * self.radius
def getPerimeter(self):
return 2 * math.pi * self.radius
|
01dd3aabd83d54a1007fac48787059d2990cf196 | daniel-reich/ubiquitous-fiesta | /oCe79PHB7yoqkbNYb_14.py | 182 | 3.5 | 4 |
def break_point(num):
num = str(num)
lst = [[[int(x) for x in num[i:]],[int(x) for x in num[:i]]] for i in range(1,len(num))]
return max([sum(x[0])==sum(x[1]) for x in lst])
|
4d1df68a9528d110fbaf1b534696d17e3cd7c009 | daniel-reich/ubiquitous-fiesta | /knWLLoi87YbCmKJS4_19.py | 365 | 3.515625 | 4 |
def happy(n):
total = 0
count = 0
n = [int(x) for x in str(n)]
while True:
for numbers in n:
total += pow(numbers, 2)
count += 1
if total > 1:
n = [int(x) for x in str(total)]
total = 0
else:
return True
if count == 10:
return False
|
b7a4d348b967de624dd0c5b44cca4d87a64ff925 | daniel-reich/ubiquitous-fiesta | /JgD9KHBYrDnKrGJ7a_1.py | 172 | 3.90625 | 4 |
def swap_dict(dic):
res = dict()
for k, v in dic.items():
if v in res:
res[v].append(k)
else:
res[v] = [k]
return res
|
811e24a79e0ef363810682b9430e7e06fe1ac388 | daniel-reich/ubiquitous-fiesta | /suhHcPgaKdb9YCrve_17.py | 255 | 4.28125 | 4 |
def even_or_odd(s):
e = 0
o = 0
for i in s:
i = int(i)
if i%2==0:
e += i
else:
o += i
if e > o:
return "Even is greater than Odd"
if o > e:
return "Odd is greater than Even"
return "Even and Odd are the same"
|
c49fc5627982ca2f6b917a9eac8756233b15b4d7 | daniel-reich/ubiquitous-fiesta | /5h5uAmaAWY3jSHA7k_0.py | 328 | 3.765625 | 4 |
def landscape_type(lst):
if any((sorted(lst[:i+1]) == lst[:i+1] and sorted(lst[i:], reverse=True) == lst[i:]) for i in range(1,len(lst)-1)):
return 'mountain'
elif any((sorted(lst[:i+1], reverse=True) == lst[:i+1] and sorted(lst[i:]) == lst[i:]) for i in range(1,len(lst)-1)):
return 'valley'
return 'neither'
|
703902a9065a6dfc034ee27b701d44b930bde0ba | daniel-reich/ubiquitous-fiesta | /4kwft4k6zebmM2BDX_10.py | 1,251 | 3.5625 | 4 |
def chi_squared_test(results):
'''
Returns the effectiveness of the Edabit influence based on the chi-squared
test as per the instructions.
'''
ALPHA1 = 6.635
ALPHA5 = 3.841 # 99% & 95% chi-square confidence intervals for this table
table = [[0,0,0] for i in range(3)] # to hold results & totals etc
table[2][2] = sum(v[0] + v[1] for _, v in results.items()) # total progs
table[0][0], table[0][1] = [v for v in results['E']]
table[1][0], table[1][1] = [v for v in results['T']] # results in table
table[0][2], table[1][2] = sum(table[0]), sum(table[1]) # row totals
table[2][0], table[2][1] = table[0][0] + table[1][0], \
table[0][1] + table[1][1] # col totals
expected = [[table[i][2]*table[2][j]/table[2][2] for j in range(2)] \
for i in range(2)]
chi_square = round(sum((table[i][j] - expected[i][j])**2/expected[i][j] \
for j in range(2) for i in range(2)), 1)
effectiveness = 'Edabitin effectiveness = 99%' if chi_square > ALPHA1 \
else 'Edabitin effectiveness = 95%' if chi_square > ALPHA5 \
else 'Edabitin is ininfluent'
return [chi_square, effectiveness]
|
77b83da06aecde35129419c8bac3fef46c7a7685 | daniel-reich/ubiquitous-fiesta | /jWHkKc2pYmgobRL8R_24.py | 468 | 3.671875 | 4 |
def distance_to_nearest_vowel(txt):
return [distance(i, s, txt) for i, s in enumerate(txt)]
def distance(i, s, txt):
vowels = ("a", "e", "i", "u", "o")
d = 0
if s in vowels:
return d
d = len(txt)
if i > 0:
for j, _s in enumerate(txt[:i][::-1]):
if _s in vowels:
d = j+1
break
if i < len(txt):
for j, _s in enumerate(txt[i:]):
if _s in vowels:
d = j if j < d else d
break
return d
|
92bc603590b4c280ff67d50e53c24b7cc572f567 | daniel-reich/ubiquitous-fiesta | /527uLRjSofaTsMu36_7.py | 111 | 3.71875 | 4 |
def get_middle(word):
return word[len(word)//2] if len(word)%2==1 else word[len(word)//2-1:len(word)//2+1]
|
8f192edd96641f3ff5b45928132fb81609474b6e | daniel-reich/ubiquitous-fiesta | /pn7QpvW2fW9grvYYE_4.py | 340 | 3.84375 | 4 |
def find_fulcrum(lst):
Fulcrum = 1
Length = len(lst)
while (Fulcrum < Length):
Left_End = Fulcrum
Right_Start = Fulcrum + 1
Left_Side = sum(lst[0:Left_End])
Right_Side = sum(lst[Right_Start:])
if (Left_Side == Right_Side):
return lst[Fulcrum]
else:
Fulcrum += 1
return -1
|
0501750ed90cfaf3cbcd1dc330bff69368da86f7 | daniel-reich/ubiquitous-fiesta | /btN6uQc3BTmLgSw5G_0.py | 736 | 3.671875 | 4 |
import itertools
directions = ((1,0), (0, 1), (-1, 0), (0, -1))
def add(p1, p2):
return (p1[0] + p2[0], p1[1] + p2[1])
def inbounds(pos, size):
return 0 <= pos[0] < size and 0 <= pos[1] < size
def spiral(n):
iter_d = itertools.cycle(directions)
c = ((n-1)//2, (n-1)//2)
yield c
dist = 1
while True:
for _ in range(2):
d = next(iter_d)
for __ in range(dist):
c = add(c, d)
if not inbounds(c, n):
return
yield c
dist += 1
def spiral_matrix(side, string):
m = [[None, ] * side for _ in range(side)]
chars = itertools.chain(iter(string), itertools.repeat('+'))
positions = spiral(side)
for p in positions:
m[p[1]][p[0]] = next(chars)
return m
|
c9cedf300fc3c597c61e73d6eb8c31dfec8d4346 | daniel-reich/ubiquitous-fiesta | /bo4REhn9paGcFoMBs_10.py | 221 | 3.8125 | 4 |
def age_difference(ages):
ages.sort()
diff = ages[-1]-ages[-2]
if diff == 0:
return "No age difference between spouses."
elif diff ==1:
return str(diff) + " year"
else:
return str(diff) + " years"
|
f0d80479e9e81ac968213bb0e6b108123cb38605 | daniel-reich/ubiquitous-fiesta | /yfTyMb3SSumPQeuhm_3.py | 417 | 3.578125 | 4 |
def fibonacci(n):
return power_fib(len(bin(n))-3)
def power_fib(k):
if k in power_fibs: return power_fibs[k]
p,q = sq5_ap(k)
power_fibs[k] = 1 + power_fib(k-1)**2*p//q
return power_fibs[k]
def sq5_ap(k):
if k in sq5_appr: return sq5_appr[k]
p,q = sq5_ap(k-1)
p,q = p**2+5*q**2, 2*p*q
sq5_appr[k] = [p,q]
return [p,q]
power_fibs = {0:1, 1:1, 2: 3, 3: 21}
sq5_appr = {3: [6016, 2688]}
|
dd747c68112ec540ca250153e1070975223ab44c | daniel-reich/ubiquitous-fiesta | /kS8tfJD2ggohQbWx7_17.py | 741 | 3.84375 | 4 |
def last_name_lensort(names):
lst = []
for i in names:
if len(lst) == 0:
lst.append(i)
else:
lst = sort(i, lst)
return lst
def sort(name, lst):
lastname = get_lastname(name)
for i in range(len(lst)):
compare_lastname = get_lastname(lst[i])
if len(lastname) < len(compare_lastname):
lst.insert(i, name)
break
elif len(lastname) == len(compare_lastname):
if ord(lastname[0]) < ord(compare_lastname[0]):
lst.insert(i, name)
else:
lst.insert(i+1, name)
break
elif i == len(lst)-1:
lst.insert(i, name)
break
return lst
def get_lastname(name):
index_space = name.find(" ")
lastName = name[index_space+1:]
return lastName
|
4276ef4479b8b578104f9d4d476e29bbb52e55da | daniel-reich/ubiquitous-fiesta | /5h5uAmaAWY3jSHA7k_8.py | 403 | 3.734375 | 4 |
def landscape_type(lst):
A=[]
for i in range(len(lst)-1):
if lst[i]<lst[i+1]:
A.append(1)
elif lst[i]>lst[i+1]:
A.append(-1)
else:
A.append(0)
B=[x for x in A if x]
c=0
for i in range(len(B)-1):
if B[i]*B[i+1]<0:
c+=1
else:
c+=0
if c!=1:
return "neither"
else:
if B[0]==1:
return "mountain"
else:
return "valley"
|
c3664b78632044428939564049e3d3501509324c | daniel-reich/ubiquitous-fiesta | /mHRyhyazjCoze5jSL_14.py | 232 | 3.671875 | 4 |
def find(s, ch):
return [i for i, ltr in enumerate(s) if ltr == ch]
def double_swap(txt, c1, c2):
a=find(txt,c1)
b=find(txt,c2)
txt=list(txt)
for j in a:
txt[j]=c2
for k in b:
txt[k]=c1
return ''.join(txt)
|
1e8ace63a967a299f52653e2d0ed2c9301487675 | daniel-reich/ubiquitous-fiesta | /GaJkMnuHLuPmXZK7h_8.py | 245 | 3.84375 | 4 |
def letters(word1, word2):
shared = ''.join(sorted(set(x for x in word1 if x in word2)))
w1 = ''.join(sorted(set(x for x in word1 if x not in word2)))
w2 = ''.join(sorted(set(x for x in word2 if x not in word1)))
return [shared,w1,w2]
|
20d2ce41962f07e9a23d5abbc59b1ff477a8bb75 | daniel-reich/ubiquitous-fiesta | /KHPFPaKpXmDeRoYQ3_20.py | 159 | 3.53125 | 4 |
def check_score(s):
symbols = {'#':5,'O':3,'X':1,'!':-1,'!!':-3,'!!!':-5}
total = sum(symbols[j] for i in s for j in i)
return total if total>0 else 0
|
bf96a889642bb4757351a8f2e8c9cdd9d7950c5f | daniel-reich/ubiquitous-fiesta | /e8TFAMbTTaEr7JSgd_1.py | 82 | 3.625 | 4 |
def left_digit(num):
for ch in num:
if ch.isdigit():
return int(ch)
|
e53dafe2ec604dcec6994a88cb616bc5bec460f7 | daniel-reich/ubiquitous-fiesta | /suhHcPgaKdb9YCrve_21.py | 261 | 4.09375 | 4 |
def even_or_odd(s):
evens=sum([int(i) for i in s if int(i)%2==0])
odds=sum([int(i) for i in s if int(i)%2!=0])
if evens>odds:
return"Even is greater than Odd"
if evens<odds:
return"Odd is greater than Even"
return"Even and Odd are the same"
|
aebbb01fd16dd079844a586bde79d10df8d0d3bc | daniel-reich/ubiquitous-fiesta | /BcjsjPPmPEMQwB86Y_14.py | 666 | 3.59375 | 4 |
def get_vowel_substrings(txt):
myans = []
v = ['a','e','i','o','u']
for i in range(len(txt)):
if txt[i] in v:
for j in range(i,len(txt)):
if txt[j] in v:
if txt[i:j+1] not in myans:
myans.append(txt[i:j+1])
return sorted(myans)
def get_consonant_substrings(txt):
myans = []
v = ['a','e','i','o','u']
for i in range(len(txt)):
if txt[i] not in v:
for j in range(i,len(txt)):
if txt[j] not in v:
if txt[i:j+1] not in myans:
myans.append(txt[i:j+1])
return sorted(myans)
|
b3a0152382073a88dae4f641986d2efc2bab5978 | daniel-reich/ubiquitous-fiesta | /xPmfKHShmuKL5Qf9u_12.py | 343 | 3.640625 | 4 |
def scale_tip(lst):
arr = []
brr = []
isSplit = False
for c in lst:
if type(c) == str:
isSplit=True
elif type(c) == int:
if isSplit:
brr.append(c)
else : arr.append(c)
a = sum(arr)
b = sum(brr)
if a == b:
return "balanced"
elif a > b:
return "left"
else : return "right"
|
5386fd3bc525e68c4303b70d4cd14f8d9b27cbec | daniel-reich/ubiquitous-fiesta | /X9CsA6955cKRApBNH_5.py | 352 | 3.609375 | 4 |
def longest_run(lst):
x = run(lst, 1)
y = run(lst, -1)
return max(x,y)
def run(lst, d):
lor = []
r = 1
prev = lst[0]
for x in lst[1:]:
if x - prev == d:
prev = x
r += 1
else:
lor.append(r)
prev = x
r = 1
lor.append(r)
return max(lor)
|
b36752ab414e24c6294e1f688ca69e77a85b890b | daniel-reich/ubiquitous-fiesta | /oTzuXDWL26gnY5a5P_9.py | 342 | 4 | 4 |
import math
def is_prime(number):
if number % 2 == 0 and number > 2:
return False
for i in range(3, int(math.sqrt(number)) + 1, 2):
if number % i == 0:
return False
return True
def prime_numbers(num):
count_prime = 0
while num > 1:
if is_prime(num):
count_prime += 1
num -= 1
return count_prime
|
f5457755be2eae2ce08b592da3ae8bce0c1b937b | daniel-reich/ubiquitous-fiesta | /bmYrX5N9DBF27Fx63_11.py | 623 | 3.53125 | 4 |
def greatest_impact(factors):
'''
Returns the factor (weather, meals, sleep) which has greatest impact on
mood, given the instructions, or nothing if no single factor predominates.
'''
FACTORS = (('Mood',10),('Weather',10),
('Meals',3),('Sleep',10)) # Factors and their scales
size = len(factors)
avgs = [sum(fac)/size/FACTORS[i][1]*100 for i, fac in enumerate(zip(*factors))]
if all(avgs[i] == avgs[0] for i in range(1,4)):
return 'Nothing'
diffs = [abs(avgs[i] - avgs[0]) for i in range(1,4)]
return FACTORS[diffs.index(min(diffs)) + 1][0]
|
94ffb00024de0b8e3abcc9b313c2d613d6e4660d | daniel-reich/ubiquitous-fiesta | /di7ZjxgvLgz72PvCS_9.py | 182 | 3.671875 | 4 |
def validate_swaps(lst, txt):
arr = [sum(1 for x,y in zip(word, txt) if x!=y) if len(word) == len(txt) else 5 for word in lst]
return [True if x == 2 else False for x in arr ]
|
5950e69406b4830e0ad329ca53ead7ff1881e122 | daniel-reich/ubiquitous-fiesta | /u7ykayCJjyQXAk7gw_11.py | 661 | 3.765625 | 4 |
animals = ["dog", "cat", "bat", "cock", "cow", "pig",
"fox", "ant", "bird", "lion", "wolf", "deer", "bear",
"frog", "hen", "mole", "duck", "goat"]
def count_animals(txt):
count = []
possible = [animal for animal in animals if all(letter in txt for letter in animal)]
for i in range(len(possible)):
ct = 0
new_txt = txt
for animal in possible:
while all(letter in new_txt for letter in animal):
ct += 1
for char in animal:
new_txt = new_txt.replace(char, '', 1)
count.append(ct)
possible.append(possible.pop(0))
return max(count)
|
99e8fa05dd00c9838cd080d1b866e0b597d18d7f | daniel-reich/ubiquitous-fiesta | /jDjDgRPpp9cTEPkKH_4.py | 1,130 | 3.5625 | 4 |
import math
from decimal import Decimal, ROUND_HALF_UP
def over_time(input_time_list):
# See if you want to put checks for timings
# input_time_list = [start_time, end_time, rate_hr, overtime_mul]
# function ->
start_time = float(input_time_list[0])
end_time = float(input_time_list[1])
rate_hr = float(input_time_list[2])
overtime_mul = float(input_time_list[3])
pay = 0
if end_time < 17.00:
normal_pay_time = end_time - start_time
else:
normal_pay_time = 17.00 - start_time
if start_time < 17.00:
overtime_hours = end_time - 17.00
else:
normal_pay_time = 0.0
overtime_hours = end_time - start_time
if end_time > 17.00:
normal_pay = normal_pay_time * rate_hr
over_time_pay = overtime_hours * overtime_mul * rate_hr
pay = normal_pay + over_time_pay
else:
pay = normal_pay_time * rate_hr
pay = Decimal(pay)
pay = Decimal(pay.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP))
pay = "$%.2f" % (pay)
return pay
|
7787e123369ef03fa9597a4d948b53ab2d05961f | daniel-reich/ubiquitous-fiesta | /eKJ8E6wnd9GMWxGaZ_1.py | 1,484 | 3.71875 | 4 |
def dolla_dolla_bills(number):
number_str = str(number)
if "." not in number_str:
number_str = number_str + ".00"
point = number_str.index(".")
if "." in number_str:
number = number_str[:point+1]
if point+3 < len(number_str):
number = number + number_str[point+1]
if int(number_str[point+3]) >= 5:
number += str(int(number_str[point+2]) + 1)
else:
number += str(int(number_str[point+2]))
else:
number_str += "0"
for index in range(point+1, point+3):
number += number_str[index]
number_str = number
length = len(number_str[:point])
if length > 3 and "." not in number_str[:point]:
newNum = []
for counter, value in reversed(list(enumerate(number_str[:point]))):
if (length-counter)%3==0:
newNum += value + ","
else:
newNum+=value
if "-" in newNum:
newNum = "".join(newNum[::-1]).strip("-").strip(",")
newNum = "-" + newNum
else:
newNum = "".join(newNum[::-1]).strip(",")
print(newNum)
number_str = newNum + "." + number[-2:]
if "-" in number_str:
l = list(number_str)
l[0] = "$"
number_str ="-" + "".join(l)
else:
number_str = "$" + number_str
return number_str
|
2edfbc43f9e0e82d2cdfaa15c425f26e1520c3ff | daniel-reich/ubiquitous-fiesta | /jozLzME3YptxydiQm_10.py | 95 | 4 | 4 |
def is_plural(word):
if word[len(word)-1] == 's':
return True
else:
return False
|
99be4253de03d582735d2a58208e2a72bcbec1cf | daniel-reich/ubiquitous-fiesta | /hzs9hZXpgYdGM3iwB_3.py | 488 | 3.953125 | 4 |
def alternating_caps(string):
word, index, spaces_position, space_index = list(string.lower()), 0, [], 0
for i in word:
if i == " ":
spaces_position.append(space_index)
space_index += 1
for i in range(0,string.count(" "),1):
word.remove(" ")
for i in word:
if index == 0 or index % 2 == 0:
word[index] = i.upper()
index+=1
for i in spaces_position:
word.insert(i, " ")
return "".join(word)
|
38c5ac7496c7754a7d46189fff682ffb535ab198 | daniel-reich/ubiquitous-fiesta | /72KukSssxk2eHrWqx_9.py | 412 | 3.609375 | 4 |
def char_at_pos(r, s):
if s == 'even':
if isinstance(r, str):
return ''.join([r[i] for i in range(len(r)) if i % 2 == 0])
return [r[-i] for i in range(1,len(r)+1) if i % 2 == 0][::-1]
elif s == 'odd':
if isinstance(r, str):
return ''.join([r[i] for i in range(len(r)) if i % 2 != 0])
return [r[-i] for i in range(1,len(r)+1) if i % 2 != 0][::-1]
|
947e719c978246df8d93911af843d71f7fc2fe18 | daniel-reich/ubiquitous-fiesta | /DpFmDxcyesPfPoFMn_23.py | 1,322 | 3.796875 | 4 |
def isbn13(txt):
if len(txt) == 10:
if not divisible_by_eleven(multiply_isbn10(txt)):
return 'Invalid'
else:
txt = '978' + txt
txt = txt[:-1] + '0'
while not divisible_by_ten(multiply_isbn13(txt)):
txt = str(int(txt)+1)
return txt
elif len(txt) == 13:
if divisible_by_ten(multiply_isbn13(txt)):
return 'Valid'
else:
return 'Invalid'
else:
return 'Invalid'
def multiply_isbn10(number):
total = 0
number = str(number)
for count, num in enumerate(number):
if num == 'x' or num == 'X':
num = 10
total += int(num) * isbn_10_keys[count+1]
return total
def multiply_isbn13(number):
total = 0
number = str(number)
for count, num in enumerate(number):
total += int(num) * isbn_13_keys[count+1]
return total
def divisible_by_ten(number):
if int(number) % 10 == 0:
return True
return False
def divisible_by_eleven(number):
if int(number) % 11 == 0:
return True
return False
isbn_10_keys = {1:10, 2:9, 3:8, 4:7, 5:6, 6:5, 7:4, 8:3, 9:2, 10:1}
isbn_13_keys = {1:1, 2:3, 3:1, 4:3, 5:1, 6:3, 7:1, 8:3, 9:1, 10:3, 11:1, 12:3, 13:1}
print(isbn13('031606652X'))
|
8a4375b023139c526f4de22570b240ae470fbf94 | daniel-reich/ubiquitous-fiesta | /MbbX7qJJeEnQu9bKr_1.py | 316 | 3.5 | 4 |
def max_occur(text):
arr = [0 for i in range(127)]
maxCount = -1
ans = -1
for i in text:
arr[ord(i)] += 1
for i in range(127):
if (arr[i] > maxCount):
maxCount = arr[i]
ans = i
if arr[ans] == 1:
return "No Repetition"
return [chr(i) for i in range(127) if arr[i] == maxCount]
|
18e60ef7e40d3a66201d24c96c3967b21a072150 | daniel-reich/ubiquitous-fiesta | /M47FDJLjfNoZ6k6gF_24.py | 183 | 3.65625 | 4 |
def cup_swapping(swaps):
current = 'B'
for i in swaps:
if current in i:
if current == i[0]:
current = i[1]
else:
current = i[0]
return current
|
1f3795e33c6ccc574c31e546e77533f749200452 | daniel-reich/ubiquitous-fiesta | /KQe5w8AdSLbweW8ck_10.py | 331 | 3.734375 | 4 |
def char_at_pos(input, position):
if position == "even":
result = [input[i] for i in range(1, len(input), 2)]
elif position == "odd":
result = [input[i] for i in range(0, len(input), 2)]
else:
return
if type(input) == str:
return ''.join(result)
return result
|
ac58fa09f08a1413da791a9f4d4c45e7954324d6 | daniel-reich/ubiquitous-fiesta | /A8gEGRXqMwRWQJvBf_11.py | 312 | 3.703125 | 4 |
def tic_tac_toe(board):
k=['O','X']
y=[]
for i in board:
for j in i:
y.append(j)
s=[[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]]
for l in k:
for i in s:
t=0
for j in i:
if(y[j]==l):
t+=1
if(t==3):
return l
return 'Draw'
|
a4913e6f2f8c280826da3b3089f43f99a8ca6c60 | daniel-reich/ubiquitous-fiesta | /iTX7sAMgekBWaq5J8_5.py | 144 | 3.8125 | 4 |
def add_up_to(n):
numbers = []
for i in range(n+1):
if n == 1:
return 1
else:
numbers.append(i)
return sum(numbers)
|
0326a6e445bac732ac038976804389b635656d1e | daniel-reich/ubiquitous-fiesta | /8xLnFm4HW4bzJrqjc_23.py | 154 | 3.75 | 4 |
def digit_distance(num1, num2):
sum = 0
for i in range(len(str(num1))):
sum = sum + abs(int((str(num1)[i])) - int((str(num2))[i]))
return sum
|
a928c07b98678feb7c532f94f0783cd3102cc1bf | daniel-reich/ubiquitous-fiesta | /527uLRjSofaTsMu36_4.py | 154 | 3.75 | 4 |
def get_middle(word):
if len(word)==0:
return word
if len(word)%2==0:
return word[len(word)//2 -1]+ word[len(word)//2]
return word[len(word)//2]
|
3a55a9f7fb3b5d0778081db8ebebc704af24d9f1 | daniel-reich/ubiquitous-fiesta | /HpJCBwggQMDLWTHsM_10.py | 142 | 3.6875 | 4 |
def average_word_length(txt):
lengths = [len(word.rstrip(',.!?')) for word in txt.split()]
return round(sum(lengths) / len(lengths), 2)
|
cca9083cebe1e4a3f283951940499546baa6b3d0 | daniel-reich/ubiquitous-fiesta | /vqMFpARj3DvELLDmZ_15.py | 83 | 3.5 | 4 |
def letters_only(txt):
a = [x for x in txt if x.isalpha()]
return "".join(a)
|
7a370b322c4531d2b3cc2655bef182510dfbf7c2 | daniel-reich/ubiquitous-fiesta | /LuBtaT9dwStbd7mnK_1.py | 138 | 3.5 | 4 |
def tallest_building_height(lst):
for i in lst:
if '#' in i:
g=lst.index(i)
break
return str((len(lst)-g)*20) + 'm'
|
54d87e190293508a0a95671d16d6664ecd3e391d | daniel-reich/ubiquitous-fiesta | /KQe5w8AdSLbweW8ck_24.py | 594 | 3.78125 | 4 |
def char_at_pos(characters, place):
if type(characters) == list:
placement = []
for char in range(len(characters)):
if (place == 'even') and (char % 2 != 0):
placement.append(characters[char])
elif (place == 'odd') and (char % 2 == 0):
placement.append(characters[char])
elif type(characters) == str:
placement = ''
for char in range(len(characters)):
if (place == 'even') and (char % 2 != 0):
placement += characters[char]
elif (place == 'odd') and (char % 2 == 0):
placement += characters[char]
return placement
|
b2e45135a5e4529707c6fa33674c060b08baaad3 | daniel-reich/ubiquitous-fiesta | /SqbyWYwqChQroXfhu_4.py | 171 | 3.703125 | 4 |
def lower_triang(arr):
for row in range(0,len(arr)):
for i in range(0,len(arr)):
if i>row:
arr[row][i] = 0
return arr
|
98dcdc1bf9415d18201d6d7064d3eb30ef79631e | daniel-reich/ubiquitous-fiesta | /FT5Zd4mayPa5ghpPt_17.py | 593 | 3.671875 | 4 |
def color_conversion(h):
if type(h) == dict:
for i in h:
if h[i] < 0 or h[i] > 255:
return "Invalid input!"
r = hex(h["r"])[2:]
g = hex(h["g"])[2:]
b = hex(h["b"])[2:]
return "#{}{}{}".format(r.zfill(2), g.zfill(2), b.zfill(2))
else:
ok = "1234567890abcdef"
h = h.replace("#", "")
if not all([i in ok for i in h]) or len(h) != 6:
return "Invalid input!"
r = int(h[:2], 16)
g = int(h[2:4], 16)
b = int(h[4:], 16)
return {"r" : r, "g" : g, "b" : b}
|
28bf72b87b0c7aec338132ea681397f89f45dd09 | daniel-reich/ubiquitous-fiesta | /gH3QMvF3czMDjENkk_15.py | 242 | 3.5625 | 4 |
def remove_letters(letters, word):
final = []
for i in letters:
if i not in word:
final.append(i)
elif i in word:
if letters.count(i) > word.count(i):
final.append(i)
letters.remove(i)
return final
|
74f81307aa904fda6994c4aafe600013970fb0ae | daniel-reich/ubiquitous-fiesta | /YxnrZQwKyrzgcMvT4_14.py | 1,144 | 3.65625 | 4 |
def rotate_transform(lst, num):
class Matrix:
def __init__(self, mtx):
self.mtx = mtx
self.cols = []
for n in range(len(self.mtx[0])):
col = []
for row in self.mtx:
col.append(row[n])
self.cols.append(col)
def rotate_clockwise(self):
self.mtx = [list(reversed(i)) for i in self.cols]
self.cols = []
for n in range(len(self.mtx[0])):
col = []
for row in self.mtx:
col.append(row[n])
self.cols.append(col)
return True
def rotate_anticlockwise(self):
self.mtx = list(reversed(self.cols))
self.cols = []
for n in range(len(self.mtx[0])):
col = []
for row in self.mtx:
col.append(row[n])
self.cols.append(col)
def rotate_x_times(self, x):
if x < 0:
for n in range(abs(x)):
self.rotate_anticlockwise()
else:
for n in range(x):
self.rotate_clockwise()
return True
matrix = Matrix(lst)
matrix.rotate_x_times(num)
return matrix.mtx
|
e157a6dd3e3814f5a59d5220d21e471beb986996 | daniel-reich/ubiquitous-fiesta | /eHwd6medMrY3QXM8k_17.py | 451 | 3.53125 | 4 |
def is_consecutive(s):
for i in range(0,len(s)):
increasing=0
j=i+1
n=int(s[:j])
count=0
while(j<len(s)):
if(s[j:].startswith(str(n+1))):
count=1
j+=len(str(n+1))
n+=1
increasing=1
elif(s[j:].startswith(str(n-1)) and increasing==0):
count=1
n-=1
j+=len(str(n-1))
else:
count=0
break
if(count==1):
return True
return False
|
92960a18ea8d9d09992cb8f0fd550297df5ad886 | daniel-reich/ubiquitous-fiesta | /gH3QMvF3czMDjENkk_7.py | 115 | 3.75 | 4 |
def remove_letters(letters, word):
for i in list(word):
if i in letters:letters.remove(i)
return letters
|
97c7a210808912f80bf794086485674222f87134 | daniel-reich/ubiquitous-fiesta | /M8jNckAgpC5ZFkhhG_7.py | 378 | 3.65625 | 4 |
def reverse_complement(input_sequence):
a = list(input_sequence)
for i in range(len(a)):
if a[i] == 'A':
a[i] = 'U'
continue
if a[i] == 'U':
a[i] = 'A'
continue
if a[i] == 'G':
a[i] = 'C'
continue
if a[i] == 'C':
a[i] = 'G'
return ''.join(a[::-1])
|
17e831e209597b4130bb59c2aadb4c97e7da8b9f | daniel-reich/ubiquitous-fiesta | /HRu9WggWxdSpYjxNf_4.py | 130 | 3.578125 | 4 |
def list_less_than_100(lst):
sum = 0
for i in lst:
sum += i
if sum < 100:
return True
else:
return False
|
1a7343a32b44745985a781b0f130fc493833d954 | daniel-reich/ubiquitous-fiesta | /xmyNqzxAgpE47zXEt_4.py | 274 | 3.953125 | 4 |
def is_alphabetically_sorted(sentence):
b=sentence.strip(".")
for word in b.split():
if len(word)>=3:
a=[]
for letter in word:
a.append(letter)
x="".join(sorted(a))
a=[]
if x==word:
return True
return False
|
8320d913f65811ee573b5a4594b2a25fce1b736f | daniel-reich/ubiquitous-fiesta | /Mm8SK7DCvzissCF2s_3.py | 129 | 3.546875 | 4 |
def is_alpha(word):
a = ' abcdefghijklmnopqrstuvwxyz'
return sum([a.index(i) for i in word.lower() if i.isalpha()])%2 == 0
|
ca04ce0783527caee95ecd01d08f8f0dab308e97 | daniel-reich/ubiquitous-fiesta | /yGhSu82pSoGjZCRDy_14.py | 306 | 4 | 4 |
def seesaw(num):
num = str(num)
if len(num) < 2:
return 'balanced'
fulcrum = len(str(num)) // 2
try:
if int(num[:fulcrum]) > int(num[-fulcrum:]):
return 'left'
if int(num[:fulcrum]) < int(num[-fulcrum:]):
return 'right'
except:
return 'balanced'
return 'balanced'
|
8ad7a9c3afde107247498e3d56724689edbb1e44 | daniel-reich/ubiquitous-fiesta | /eRY7eBD8dan54acgG_5.py | 264 | 3.734375 | 4 |
def is_checkerboard(lst):
for i in range (len(lst)):
for j in range (1,len(lst)):
if lst[i][j]==lst[i][j-1]: return False
for j in range (len(lst)):
for i in range (1,len(lst)):
if lst[i][j]==lst[i-1][j]: return False
return True
|
122bc4568e2717dcead20e371fde08419db044d7 | daniel-reich/ubiquitous-fiesta | /BfSj2nBc33aCQrbSg_3.py | 1,178 | 3.6875 | 4 |
import numpy
from math import floor
def primesfrom3to(n):
""" Returns a array of primes, 3 <= p < n """
sieve = numpy.ones(n//2, dtype=numpy.bool)
for i in range(3,int(n**0.5)+1,2):
if sieve[i//2]:
sieve[i*i//2::i] = False
return 2*numpy.nonzero(sieve)[0][1::]+1
def pruneNum(num):
if (len(str(num))==1): return ''
numb = list(str(num))
numb.remove(numb[0])
return int(''.join(numb))
def checkRL(num, rl, primes):
if (rl=="r"):
while len(list(str(num)))!=1:
num = floor(num/10)
if (num not in primes and num!=2): return False
return True
else:
while len(list(str(num)))!=1:
num = pruneNum(num)
if (num not in primes and num!=2): return False
return True
def truncatable(n):
answer, primes = [], primesfrom3to(n+1)
checkedR, checkedL = checkRL(n, "r", primes), checkRL(n, "l", primes)
if ('0' in list(str(n))): return False
elif (n not in primes): return False
if (checkedR==True): answer.append("right")
if (checkedL==True): answer.append("left")
if ("right" in answer and "left" in answer): answer = ["both"]
if (answer == []): answer=[False]
return answer[0]
|
c2e5802cffe9d855b304367a42d8822ce5827531 | daniel-reich/ubiquitous-fiesta | /ojBNREQrg7EW9ZzYx_15.py | 411 | 4.0625 | 4 |
import re
def count_eatable_chocolates(total_money, cost_of_one_chocolate):
regex = r"(-?\d+)"
total = int(re.search(regex,total_money).group(1))
cost = int(re.search(regex,cost_of_one_chocolate).group(1))
if total <= 0 or cost <= 0:
return "Invalid Input"
start = total // cost
counter = start
while start >= 3:
counter += start // 3
start = start // 3 + start % 3
return counter
|
a40181af6a873de0f57e569b7693af6c596fba26 | daniel-reich/ubiquitous-fiesta | /XsqET8hSTBG2AR5kM_19.py | 150 | 3.515625 | 4 |
def letter_distance(txt1, txt2):
return sum(abs(ord(txt1[i])-ord(txt2[i])) for i in range(min([len(txt1),len(txt2)]))) + abs(len(txt1)-len(txt2))
|
a9d07ee77bf3901eb028b9f7ada2ae69d446a098 | daniel-reich/ubiquitous-fiesta | /YrNbakR7Y4vLz6bFs_5.py | 936 | 3.5 | 4 |
def combinator(lst, string = None):
if len(lst) == 1:
return lst[0]
if string != None:
tr = []
if len(lst) == 2:
a, b = lst
if [] in [a, b]:
return []
for item in a:
for itm in b:
tr.append(item + string + itm)
if len(lst) == 3:
a, b, c = lst
if [] in [a, b, c]:
return []
for item in a:
for itm in b:
for it in c:
tr.append(string.join([item, itm, it]))
return tr
if len(lst) == 2:
a, b = lst
if a == [] or b == []:
return []
tr = []
for item in a:
for itm in b:
tr.append(item + itm)
if len(lst) == 3:
a, b, c = lst
if a == [] or b == []:
return []
tr = []
for item in a:
for itm in b:
for it in c:
tr.append(item + itm + it)
return tr
|
78a7dee9238563c55f87fc478d9eca74dc2fe877 | daniel-reich/ubiquitous-fiesta | /A9iPfSEZ9fCrPQSwC_13.py | 191 | 3.71875 | 4 |
def points_in_circle(points, centerX, centerY, radius):
import math
return sum([1 for point in points if math.sqrt((centerX-point.get('x'))**2 + (centerY-point.get('y'))**2) < radius])
|
aec33df3bee426e02e217fb11ce03ed9fbda79da | daniel-reich/ubiquitous-fiesta | /TkL6GTu9QMhYnv869_21.py | 95 | 3.53125 | 4 |
def add_ending(lst, ending):
for i in lst:
lst[lst.index(i)] = i + ending
return lst
|
cb853b8622b9db0e0719a3a61327853429245822 | daniel-reich/ubiquitous-fiesta | /QB6kPXQkFgMkzcc2h_18.py | 182 | 3.640625 | 4 |
def remove_abc(txt):
if txt.find("a") == -1 and txt.find("b") == -1 and txt.find("c") == -1:
return
else:
return txt.replace("a", "").replace("b", "").replace("c", "")
|
a4ea88d6bba7313ce67eb6a566b7205a156d8206 | daniel-reich/ubiquitous-fiesta | /4bX7qAqELq9XJeB26_5.py | 310 | 4.0625 | 4 |
def to_camel_case(txt):
txt = [i for i in txt]
for i in range(len(txt)):
if txt[i-1] == "-" or txt[i-1] == "_":
txt[i] = txt[i].upper()
txt = "".join(txt)
if "_" in txt:
txt = txt.replace("_","")
if "-" in txt:
txt = txt.replace("-","")
return txt
|
99cebcf076b01f608d82147d283e1a31933651d0 | daniel-reich/ubiquitous-fiesta | /4AzBbuPLxKfJd7aeG_12.py | 347 | 3.671875 | 4 |
def encrypt(key, message):
l=['#']
for i in range(0,len(key),2):
l.append(key[i])
l.append(key[i+1])
l.append('#')
en=''
for i in message:
j=str.lower(i)
if(j not in l):
en+=i
else:
index=l.index(i)
if(l[index-1]=='#'):
en+=l[index+1]
else:
en+=l[index-1]
return en
|
fc486c9d6ee3debe11bb40f226cd95417580f624 | daniel-reich/ubiquitous-fiesta | /bupEio82q8NMnovZx_19.py | 336 | 3.765625 | 4 |
def track_robot(instructions):
x = 0
y = 0
for i in instructions:
direction = i.split()
if direction[0] == 'up':
y += int(direction[1])
elif direction[0] == 'down':
y -= int(direction[1])
elif direction[0] == 'left':
x -= int(direction[1])
else:
x += int(direction[1])
return [x,y]
|
2e2500caa200918b14352348d4dd56dddcc1ea81 | daniel-reich/ubiquitous-fiesta | /6Pf5GGG6HnzbB95gf_21.py | 162 | 3.515625 | 4 |
def find_factors(n):
if n < 1:
return []
res = []
for i in range(1,int(n/2) + 1):
if n % i == 0:
res.append(i)
res.append(n)
return res
|
cd78f9d2469580de6fed6dddec20288e1f1b0554 | daniel-reich/ubiquitous-fiesta | /wW2z9bRi2bTeAbcqY_5.py | 174 | 3.71875 | 4 |
def solve(a, b):
if a==1:
if b==1:
return 'Any number'
else:
return 'No solution'
else:
return round((b-1)/(a-1),3)
|
67c7e15109d5201d2f42b1ddb1158e77acf794f1 | daniel-reich/ubiquitous-fiesta | /RejGBWcKsKM2PANip_9.py | 100 | 3.71875 | 4 |
def number_syllables(word):
a = 0
for i in word:
if(i == '-'):
a = a+1
return a+1
|
979b7a2e087b976d18fa8124ebe2ea27f2607ba0 | daniel-reich/ubiquitous-fiesta | /ucsJxQNrkYnpzPaFj_3.py | 165 | 3.734375 | 4 |
def char_appears(sentence, char):
result = []
divided = sentence.split(" ")
for word in divided:
result.append(word.lower().count(char))
return result
|
d8bb4a8847a0697e181ea546dc8a881d3cb53cc1 | daniel-reich/ubiquitous-fiesta | /YSJjPdkwrhQCfnkcZ_20.py | 175 | 3.734375 | 4 |
def repeat_string(txt, n):
if isinstance(txt, str):
lst = [txt] * n
result = ''.join(lst)
else:
result = 'Not A String !!'
return result
|
509a0741a1af5d9f5242668b6c110dca56959525 | daniel-reich/ubiquitous-fiesta | /SLCqbNTy4aacoNjvw_22.py | 105 | 3.515625 | 4 |
def remove_dups(lst):
res = []
for l in lst:
if l not in res:
res.append(l)
return res
|
280b845a106c503186334374f3b8a19f9b335d58 | daniel-reich/ubiquitous-fiesta | /dcX6gmNguEi472uFE_12.py | 232 | 4.34375 | 4 |
def factorial(num):
fact = 1
while num > 0:
fact = fact*num
num -= 2
return fact
def double_factorial(num):
print(num)
if num == 0 or num == 1 or num == -1:
return 1
else:
return num * factorial(num-2)
|
8eac74a6ec9a8af744f53e025f4af73d344636c7 | daniel-reich/ubiquitous-fiesta | /hv572GaPtbqwhJpTb_22.py | 305 | 3.546875 | 4 |
def elasticize(word):
lw=len(word)
p=lw//2
r=m=''
if lw%2!=0:
m=word[p]
word=word[:p]+word[p+1:]
lw-=1
k=-2*p-1
for i in range(lw):
k+=2
r+=word[i]*((i+1)-(i>p-1)*k)
if m!='':
r=r[:len(r)//2]+m*(p+1)+r[len(r)//2:]
return r
|
fa4b4776ca8e329698a58f3e4cb5d1cbba78ca45 | daniel-reich/ubiquitous-fiesta | /CzrTZKEdfHTvhRphg_20.py | 589 | 3.6875 | 4 |
def pgcd(num1, num2):
for val in range(min(num1, num2), 0, -1):
if num2%val == 0 and num1%val == 0 : return val
def mixed_number(frac):
up, down = list(map(lambda elm: int(elm), frac.split('/')))
if up == 0: return '0'
up = abs(up)
div = pgcd(up, down)
up, down = up//div, down//div
num = up//down
result = '-' if frac[0] == '-' else ''
if num == up/down: return result + str(num)
result += str(num)+' ' if num != 0 else ''
result += str(up - num*down) + '/' + str(down) if num != up/down else str(num)
return result
|
684161d0737461e3ed16002c98a195deb0f8d4e9 | daniel-reich/ubiquitous-fiesta | /662nTYb83Lg3oNN79_13.py | 375 | 3.875 | 4 |
def is_parallelogram(a):
a1=a[1][0]-a[0][0]
a2=a[2][0]-a[0][0]
a3=a[2][0]-a[3][0]
a4=a[1][0]-a[3][0]
a5=a[3][0]-a[1][0]
b1=a[1][1]-a[0][1]
b2=a[2][1]-a[0][1]
b3=a[2][1]-a[3][1]
b4=a[1][1]-a[3][1]
b5=a[3][1]-a[1][1]
if(a1==a3 and b1==b3):
return(True)
elif(a2==a4 and b2==b4):
return(True)
elif(a2==a5 and b2==b5):
return(True)
else:
return(False)
|
227a3a1d4015a20659dfc9881037d95b9efa0e28 | daniel-reich/ubiquitous-fiesta | /GZ5gCe5jnbNRWqc5J_17.py | 349 | 3.921875 | 4 |
def first_tuesday_of_the_month(year, month):
from datetime import date as d
day = 1
while d(year, month, day).weekday() != 1:
day += 1
year, month, day = [str(item) for item in [year, month, day]]
while len(month) < 2:
month = '0' + month
while len(day) < 2:
day = '0' + day
return '-'.join([year, month, day])
|
c8abc44e9efe015c73f61d6d304baba0142c068f | daniel-reich/ubiquitous-fiesta | /si2H6WC5YX99cn6LQ_8.py | 90 | 3.578125 | 4 |
def sum_numbers(n):
if n == 1:
return n
else:
return n + sum_numbers(n - 1)
|
a48ceb55e51dd6b1f21d41db6cddb047fada0e51 | daniel-reich/ubiquitous-fiesta | /Lx9mL2uBWwtJFv94a_5.py | 802 | 3.90625 | 4 |
def make_row_odd(n, el1, el2):
Colcounter = 0
line = []
while Colcounter < n:
if Colcounter % 2 == 0:
line.append(el1)
else:
line.append(el2)
Colcounter += 1
return line
def make_row_even(n, el1, el2):
Colcounter = 0
line = []
while Colcounter < n:
if Colcounter % 2 == 0:
line.append(el2)
else:
line.append(el1)
Colcounter += 1
return line
def build_board(n, el1, el2):
Rowcounter = 0
result = []
while Rowcounter < n:
if Rowcounter % 2 == 0:
result.append(make_row_odd(n, el1, el2))
else:
result.append(make_row_even(n, el1, el2))
Rowcounter += 1
print(result)
return result
def checker_board(n, el1, el2):
if el1 == el2:
return "invalid"
else:
return build_board(n, el1, el2)
|
3912bd15564144ca1686b7d840a784c7638218db | daniel-reich/ubiquitous-fiesta | /ivWdkjsHtKSMZuNEc_0.py | 204 | 4.03125 | 4 |
import re
def find_shortest_words(txt):
txt = re.sub(r"[^a-zA-Z ]","",txt)
mLen = min([len(word) for word in txt.split()])
return sorted([word.lower() for word in txt.split() if len(word)==mLen])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.