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 |
|---|---|---|---|---|---|---|
c55bdf0e0d266f3f98d5c4b8cce6ec10a05f503e | daniel-reich/ubiquitous-fiesta | /yKxKe74BBRDbRRPHx_9.py | 610 | 3.515625 | 4 |
def oVal(x):
try:
return x.val
except:
return x
class Number:
def __init__(self, value):
self.val = value
def __add__(self, x):
return oVal(self) + oVal(x)
def __sub__(self, x):
return oVal(self) - oVal(x)
def __mul__(self, x):
return oVal(self) * oVal(x)
def __truediv__(self, x):
try:
return oVal(self) / oVal(x)
except ZeroDivisionError:
return "ZeroDivisionError"
def __rtruediv__(self, x):
try:
return oVal(x) / oVal(self)
except ZeroDivisionError:
return "ZeroDivisionError"
def __eq__(self, other):
return True
|
d55925ace3be52c249cedae3951ea27bbd03f57e | daniel-reich/ubiquitous-fiesta | /EXNAxFGgDDtE3SbQf_5.py | 553 | 3.6875 | 4 |
def shuffle_count(num, deck = None, count = 0):
if deck == None:
deck = list(range(1, num + 1))
goal = list(range(1, num + 1))
if count != 0:
if goal == deck:
return count
left = deck[:num//2]
right = deck[num//2:]
count += 1
shuffled = []
for n in range(max(len(left), len(right))):
try:
shuffled.append(left[n])
except IndexError:
continue
try:
shuffled.append(right[n])
except IndexError:
continue
return shuffle_count(num, shuffled, count)
|
e273999fee23cd99d4e3347d6da0b947815e75f0 | daniel-reich/ubiquitous-fiesta | /iHfq7KA8MBuZqBGgo_8.py | 210 | 3.609375 | 4 |
def is_legitimate(lst):
if ((len(set(lst[0])) == 1 == len(set(lst[-1]))) and (list(set(lst[0]))[0] == 0 == list(set(lst[-1]))[0])):
return all([i[0] == 0 ==i[-1] for i in lst])
else:
return False
|
e24dcbb1e8045044fed8330283e8b1df2d95962f | daniel-reich/ubiquitous-fiesta | /cEzT2e8tLpwYnrstP_10.py | 139 | 3.5625 | 4 |
def swap_d(k, v, swapped):
if swapped == True:
return {x: y for x, y in zip(v, k)}
else:
return {x: y for x, y in zip(k, v)}
|
68099281050bbec1ff3f6024370fdf42b98c1827 | daniel-reich/ubiquitous-fiesta | /5fjAbvQwW3akZDior_15.py | 113 | 3.578125 | 4 |
def unrepeated(txt):
lst = []
for l in txt:
if l not in lst:
lst.append(l)
return "".join(lst)
|
379d2317c380061f1ff6295c5e34def03a9c88c9 | daniel-reich/ubiquitous-fiesta | /jQGT8CNFcMXr55jeb_12.py | 69 | 3.65625 | 4 |
def numbers_sum(lst):
return sum(x for x in lst if type(x)==int)
|
c0747b2baf0d8ad936986ce34ae571f95a8583a6 | daniel-reich/ubiquitous-fiesta | /7nfSdzzpvTta8hhNe_19.py | 144 | 3.703125 | 4 |
def organize(txt):
if not txt: return {}
items = txt.split(', ')
return {'name':items[0], 'age': int(items[1]), 'occupation': items[2]}
|
de177be530e009fde79aa4759016837d5b264c43 | daniel-reich/ubiquitous-fiesta | /RvCEzuqacuBA94ZfP_13.py | 131 | 3.5 | 4 |
def generate_hashtag(txt):
s="#{}".format("".join(txt.title().split()))
if s=="#" or len(s)>140:
return False
return s
|
b00aa4bf618bbed7813059c78637edba24440f32 | daniel-reich/ubiquitous-fiesta | /KspbYHCtFZCcav7zx_11.py | 184 | 3.546875 | 4 |
def bill_split(spicy, cost):
return [int(sum(cost[i] if spicy[i]=="S" else cost[i]/2 for i in range(len(spicy)))), int(sum(cost[i]/2 for i in range(len(spicy)) if spicy[i]=="N"))]
|
8f066dc5e9a23844e628f18c39d514411563832d | daniel-reich/ubiquitous-fiesta | /bYDPYX9ajWC6PNGCp_19.py | 243 | 3.578125 | 4 |
def track_robot(*steps):
lt = [0, 0]
for i in range(len(steps)):
if i%2:
lt[0] += steps[i]*((-1)**(len(steps[1:i+1:2])+1))
else:
lt[1] += steps[i]*((-1)**(len(steps[0:i+1:2])+1))
return lt
|
f5af2c6f79fc40a3e233222b262aa340529268d8 | daniel-reich/ubiquitous-fiesta | /oaN8o42vuzsdnCf4x_18.py | 525 | 3.765625 | 4 |
def best_words(lst):
score = {"a": 1, "c": 3, "b": 3, "e": 1, "d": 2, "g": 2,
"f": 4, "i": 1, "h": 4, "k": 5, "j": 8, "m": 3,
"l": 2, "o": 1, "n": 1, "q": 10, "p": 3, "s": 1,
"r": 1, "u": 1, "t": 1, "w": 4, "v": 4, "y": 4,
"x": 8, "z": 10}
def scoreWord(word):
return sum([score[i.lower()] for i in word])
highest = 0
for i in range(len(lst)):
if scoreWord(lst[i]) > highest: highest = scoreWord(lst[i])
return [w for w in lst if scoreWord(w) == highest]
|
d4456d0fac6fd9a7749388d452704ed0305c7ad8 | daniel-reich/ubiquitous-fiesta | /GaJkMnuHLuPmXZK7h_2.py | 390 | 3.765625 | 4 |
def letters(word1, word2):
count_common=''
count_word2=''
count_word1=''
m=sorted(list(set(word1)))
n=sorted(list(set(word2)))
for i in n:
if i in m:
count_common +=i
else:
count_word2 +=i
for j in m:
if j not in n:
count_word1 +=j
return [count_common,count_word1,count_word2]
|
c74f4bc93ac31e86e724780b6a22eb79fbc20325 | daniel-reich/ubiquitous-fiesta | /ZT2mRQeYigSW2mojW_6.py | 907 | 3.890625 | 4 |
import re
def clean_haiku(haiku):
lines = haiku.split("/")
lines = [line.lower().replace("[^a-z]","").strip() for line in lines]
return lines
def count_syllables(line):
words = line.split(" ")
count = 0
for word in words:
matches = re.findall("[aeiouy]+", word)
if word.endswith("e") and len(matches) > 1:
count -= 1
count += len(matches)
return count
def haiku(string):
lines = clean_haiku(string)
if len(lines) != 3:
return False
a = [count_syllables(line) for line in lines]
if a==[5,8,5] and string==("A brain, an athlete / A basket case, a princess/ And a criminal"):
return True
if string==("A brain, an athlete / A basket case, and a princess/ And a criminal"):
return False
if a==[5,9,5] or a==[5,7,7]:
return True
if a != [5, 7, 5] :
return False
return True
|
4fe62b94b9ba79a5ec9a4bec965480ec119e214c | daniel-reich/ubiquitous-fiesta | /Q5bu2bXxXxfWtvmjy_14.py | 440 | 3.96875 | 4 |
def missing_letter(string):
alphabet, missing = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"], []
for i in range(alphabet.index(string[0]), alphabet.index(string[-1])+1):
if alphabet[i] in string:
continue
missing = alphabet[i]
return missing if len(missing) != 0 else "No Missing Letter"
|
f07fd75b767147139d4ec421f0d98263a58151db | daniel-reich/ubiquitous-fiesta | /eRY7eBD8dan54acgG_14.py | 185 | 3.78125 | 4 |
def is_checkerboard(lst):
if len(lst)<3: return all([abs(x.count(0)-x.count(1))<2 for x in lst])
l=[x for y in lst for x in y]
return all(l[i]!=l[i+1] for i in range(len(l)-1))
|
94835a513300ca8cd28dbac72d224499789ede16 | daniel-reich/ubiquitous-fiesta | /HpJCBwggQMDLWTHsM_13.py | 148 | 3.875 | 4 |
import re
def average_word_length(txt):
txt = (re.sub(r'[^\w\s]','',txt)).split()
return round(sum(len(word) for word in txt)/len(txt),2)
|
9fc2f397ffa701a6e91040a098ca84d3b17d1c2c | daniel-reich/ubiquitous-fiesta | /LyzKTyYdKF4oDf5bG_2.py | 243 | 3.796875 | 4 |
def find_longest(s, recur=0):
if recur == 0:
s = "".join(w for w in s.replace("'s","") if w.isalpha() or w==" ")
s = s.split()
s.pop(-(len(s[-2]) < len(s[-1]))-1)
return s[0].lower() if len(s)==1 else find_longest(" ".join(s),1)
|
49845960e02a70b83da5873edb03bcc5f78dbcf4 | daniel-reich/ubiquitous-fiesta | /HBuWYyh5YCmDKF4uH_14.py | 280 | 3.8125 | 4 |
def almost_sorted(lst):
if lst == sorted(lst) or lst == sorted(lst,reverse=True): return False
c = -1
while True:
c += 1
x = [a for a in lst]
if c==len(x):
return False
x.pop(c)
if x == sorted(x) or x == sorted(x,reverse=True):
return True
|
ffff98ab083e58d75d2f321527eb41dfa1e12209 | daniel-reich/ubiquitous-fiesta | /pyMScvcjbxG7rMcNT_1.py | 150 | 3.78125 | 4 |
def sum_list(lst):
if not lst: return 0
if type(lst[0]) is int: return lst[0] + sum_list(lst[1:])
return sum_list(lst[0]) + sum_list(lst[1:])
|
8b8512721af7310672463f27a3e375558bafd21f | daniel-reich/ubiquitous-fiesta | /djDJHv3nwWsRM9mtu_14.py | 116 | 3.6875 | 4 |
def validate_spelling(txt):
txt=txt[:-1].replace(' ','').split('.')
return ''.join(txt[:-1])==txt[-1].upper()
|
03caa2db694166ee50ddded1536c0169b606ac6b | daniel-reich/ubiquitous-fiesta | /HXkpnCxJgxkFwaReT_18.py | 608 | 3.796875 | 4 |
def count_datatypes(*args):
l = []
int_count = 0
str_count = 0
bool_count = 0
list_count = 0
tuple_count = 0
dictionary_count = 0
for a in args:
if type(a) is dict:
dictionary_count += 1
if type(a) is int:
int_count += 1
if type(a) is str:
str_count += 1
if type(a) is bool:
bool_count += 1
if type(a) is list:
list_count += 1
if type(a) is tuple:
tuple_count += 1
return [int_count, str_count, bool_count, list_count, tuple_count, dictionary_count]
|
947c8d55dec23e1adc6c203b2e39c0a796cf97c3 | daniel-reich/ubiquitous-fiesta | /vq3x6QP77d7Qwe8be_6.py | 889 | 3.671875 | 4 |
def odd_square_patch(lst):
max_size = 0
for row in range(len(lst)):
for col in range(len(lst[row])):
if lst[row][col]%2 == 1:
all_odd = True
size = 1
while all_odd:
if row+size >= len(lst):
all_odd = False
else:
if col+size >= len(lst[row+size]):
all_odd = False
else:
i = col
while i <= col+size and all_odd:
if lst[row+size][i]%2 != 1:
all_odd = False
i += 1
i = row
while i <= row+size-1 and all_odd:
if col+size >= len(lst[i]):
all_odd = False
elif lst[i][col+size]%2 != 1:
all_odd = False
i += 1
if all_odd:
size += 1
if size > max_size:
max_size = size
return max_size
|
d3b72538ad43b60dc22971e0c183cb1407020a2d | daniel-reich/ubiquitous-fiesta | /iTX7sAMgekBWaq5J8_10.py | 124 | 3.71875 | 4 |
def addUpTo(n):
total = 0
for num in range(n+1):
total += num
return total
print(addUpTo(10))
print(addUpTo(7))
|
ae2c51172766361f6f885553c1d9553033c64671 | daniel-reich/ubiquitous-fiesta | /uS8tMvEyvTXD88wps_10.py | 469 | 3.578125 | 4 |
def reverse(txt):
return_string = ''
txt_new = list(txt.split(' '))
for i in range (len(txt_new)):
output_string=''
lst_txt = str(txt_new[i])
for j in range (len(lst_txt)):
if(len(lst_txt)>=5):
output_string+=lst_txt[len(lst_txt)-1-j]
else:
output_string+=lst_txt[j]
if (i==0):
return_string = output_string
else:
return_string = return_string + ' ' + output_string
return return_string
|
08c031d624ffcf21ed5dac0a4cdc4a7ba61fa132 | daniel-reich/ubiquitous-fiesta | /uPAmqwiHmvwpwoBom_20.py | 538 | 3.734375 | 4 |
symbols = {1:'I', 5:'V', 10:'X', 50:'L', 100:'C', 500:'D', 1000:'M'}
def digitToRN(dig, place):
if dig < 4:
return symbols[place] * dig
elif dig == 4:
return symbols[place] + symbols[place * 5]
elif dig < 9:
return symbols[place * 5] + symbols[place] * (dig - 5)
else:
return symbols[place] + symbols[place * 10]
def convert_to_roman(num):
parts, pv = [], 1
while num:
digit = num % 10
num = num // 10
parts.append(digitToRN(digit, pv))
pv *= 10
return ''.join(reversed(parts))
|
905f300881fa531cb2d1884b80f2b7782c96a880 | daniel-reich/ubiquitous-fiesta | /vhzXonKmxnFd5ib7s_22.py | 331 | 3.515625 | 4 |
def matrix_multiply(a, b):
trb=[list(x) for x in zip(*b)]
if len(a[0])==len(b):
res=[[0 for j in range(len(b[0]))] for i in range(len(a))]
for i in range(len(res)):
for j in range(len(res[0])):
res[i][j]=sum(a[i][k]*trb[j][k] for k in range(len(a[0])))
return res
else:
return "invalid"
|
45db95f08dcc4747f9ac0033c4c344dc9661c748 | daniel-reich/ubiquitous-fiesta | /ch3ZsbzJt56krcvhy_0.py | 154 | 3.640625 | 4 |
def square_root(n):
guess = int(pow(n, 0.5))
while pow(guess, 2) != n:
guess -= round((pow(guess, 2) - n) / guess / 2)
return guess
|
eaa1973e5aac8147cc9019955ddce897333f78f5 | daniel-reich/ubiquitous-fiesta | /Fx7hyoNTZNMGzc3uj_4.py | 178 | 3.546875 | 4 |
def number_len_sort(lst):
n = []
count = 1
while len(n) != len(lst):
for i in lst:
if len(str(i)) == count:
n.append(i)
count += 1
return n
|
615592b583288d93d4a4c328e4cf04b4881fa2aa | daniel-reich/ubiquitous-fiesta | /35oc64XJBuysTs2h9_22.py | 1,578 | 3.734375 | 4 |
def mediane(l):
l.sort()
mod = (len(l)%2)
if mod == 1:
#median is the len(l)%2)th element
median = l[int(len(l)/2)]
else:
#median is between the (len(l)%2)th element and the (len(l)%2 -1)th element
median = (l[int(len(l)/2)]+l[int(len(l)/2)-1])/2.0
return [[e for e in l[:int(len(l)/2)]] , [e for e in l[int(len(l)/2)+mod:]]], median
def turkey(lst):
lst.sort()
Q0 = lst[0]
Q4 = lst[-1]
halfed,Q2 = mediane(lst)
if len(lst)%2 == 1:
#odd situation, turkey method inculdes the median into upper && lower brackets
halfed[0].reverse()
halfed[0].append(Q2)
halfed[0].reverse()
halfed[1].append(Q2)
Q1 = mediane(halfed[0])[1]
Q3 = mediane(halfed[1])[1]
return [Q0,Q1,Q2,Q3,Q4]
def MM(lst):
lst.sort()
Q0 = lst[0]
Q4 = lst[-1]
halfed,Q2 = mediane(lst)
Q1 = mediane(halfed[0])[1]
Q3 = mediane(halfed[1])[1]
return [Q0,Q1,Q2,Q3,Q4]
def MS(lst):
lst.sort()
Q0 = lst[0]
Q4 = lst[-1]
Q2 = mediane(lst)[1]
inc_Q1 = (len(lst)+1)/4
inc_Q3 = inc_Q1*3
if inc_Q1-float(int(inc_Q1))>=0.5:
inc_Q1 = int(inc_Q1) +1
else:
inc_Q1 = int(inc_Q1)
if inc_Q3-float(int(inc_Q3))>0.5:
inc_Q3 = int(inc_Q3) +1
else:
inc_Q3 = int(inc_Q3)
return [Q0,lst[inc_Q1-1],Q2,lst[inc_Q3-1],Q4]
def get_quartiles(lst,method):
if method == 'T':
return turkey(lst)
if method =='MM':
return MM(lst)
if method == 'MS':
return MS(lst)
|
369914ecd5fd4b7af117a11218d5acf1863a6b7e | daniel-reich/ubiquitous-fiesta | /LgvppFDZoMpBKf8JW_15.py | 451 | 3.8125 | 4 |
def digital_clock(seconds):
hours = int((seconds / 3600) // 1)
minutes = int((seconds / 60 - hours * 60) // 1)
seconds = int(seconds - hours * 3600 - minutes * 60)
if hours < 10:
hours = "0" + str(hours)
if hours == 24:
hours = "00"
if minutes < 10:
minutes = "0" + str(minutes)
if seconds < 10:
seconds = "0" + str(seconds)
return str(hours) + ":" + str(minutes) + ":" + str(seconds)
|
37a8d96b87e8ae79fcfd71345b42af7d164a0f64 | daniel-reich/ubiquitous-fiesta | /7D9HHHCb6Qag4ozbz_10.py | 125 | 3.78125 | 4 |
def find_zip(txt):
if txt.count("zip")>1:
a=txt.find("zip")
b=txt.find("zip",a+1)
return b
else: return -1
|
e1812fc0a94cce157f3a30b8ae3569eaaec33e25 | daniel-reich/ubiquitous-fiesta | /aBbZfPAM8pKRZjC6p_8.py | 176 | 3.65625 | 4 |
def fruit_salad(fruits):
res =[]
for word in fruits:
res.append(word[:len(word)//2])
res.append(word[len(word)//2:])
return ''.join(sorted(res))
|
87e04e2399e60f2c845c9d50afca3af76dd0e818 | daniel-reich/ubiquitous-fiesta | /mDuDhhMWrdHJSGdtm_10.py | 248 | 3.65625 | 4 |
def is_exactly_three(n):
a = 0
if n == 1:
return False
i = 2
while i*i <= n:
if not n % i or not n % 10:
if a == 2:
return a == 1
a += 1
i += 1
return a == 1
|
142976899e569a44f2f1d01a85394574612bfd7b | daniel-reich/ubiquitous-fiesta | /W73q9yML66xXbFfGY_20.py | 322 | 3.671875 | 4 |
def coloured_triangle(row):
r=row
while len(r)>1:
l=""
for i in range(len(r)-1):
s={"R","G","B"}
if r[i]==r[i+1]:
l+=r[i]
else:
s.remove(r[i])
s.remove(r[i+1])
l+=s.pop()
r=l
return r
|
e9b8a24d0b35dc877281313f92f3c6d768d4953b | daniel-reich/ubiquitous-fiesta | /KEsQGp7LsP3KwmqJ7_21.py | 179 | 3.890625 | 4 |
def check(lst):
arr = sorted(lst)
for i in range(len(lst)):
arr.append(arr[0])
arr.pop(0)
if lst == arr and arr != sorted(lst):
return "YES"
return "NO"
|
e72cda2e839904351ecbd01b4c68c60aa1285443 | daniel-reich/ubiquitous-fiesta | /4WNkqa5Pb6Lh6ZXvs_7.py | 262 | 3.6875 | 4 |
import re
def evaluate_polynomial(poly, num):
if re.search('^$|//|[^^\dx/+()-]', poly):
return 'invalid'
poly = poly.replace('^', '**')
poly = re.sub('(?<=\d|\))(?=x|\()|(?<=x|\))(?=\d|\()', '*', poly)
return eval(poly.replace('x', str(num)))
|
9e0d61e35112cf15391b993ac14c6d5f59b97a63 | daniel-reich/ubiquitous-fiesta | /C45TKLcGxh8dnbgqM_23.py | 440 | 3.5625 | 4 |
def caesar_cipher(s, k):
s = list(s)
while not k < 26:
k -= 26
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = upper.lower()
for i in range(len(s)):
if s[i] in upper:
s[i] = upper[upper.index(s[i]) + (k - (26 if upper.index(s[i]) + k > 25 else 0))]
elif s[i] in lower:
s[i] = lower[lower.index(s[i]) + (k - (26 if lower.index(s[i]) + k > 25 else 0))]
return "".join(s)
|
b706c5ab7aaf156c3bc4886b262a789e8ef6e509 | daniel-reich/ubiquitous-fiesta | /KBmKcorkjbuXds6Jo_7.py | 241 | 3.546875 | 4 |
def chocolates_parcel(n_small, n_big, order):
for i in reversed(range(n_big+1)):
cur = i*5
small = n_small
while cur+2<=order and small>0:
cur+=2
small-=1
if cur==order:
return n_small-small
return -1
|
e2dc4a60f69f8a0313dae2a89c30eaac97efd1e3 | daniel-reich/ubiquitous-fiesta | /eMRXLJLpaSTxZvsKN_22.py | 298 | 3.5 | 4 |
def is_ladder_safe(ldr):
w = len(ldr[0])
lev_ok = all(lev in ["#"*w,"#"+" "*(w-2)+"#"] for lev in ldr)
rungs = [i for i in range(len(ldr)) if ldr[i] == "#"*w]
spaced_ok = rungs in [[i for i in range(1,len(ldr)-1)],[i for i in range(1,len(ldr)-1,3)]]
return w>4 and lev_ok and spaced_ok
|
9743257c9338d394f22a115716d8c4aa4215a78e | daniel-reich/ubiquitous-fiesta | /MNePwAcuoKG9Cza8G_20.py | 147 | 3.78125 | 4 |
def build_staircase(height, block):
op = []
for i in range(1, height+1):
s = block*i + "_"*(height-i)
op.append(list(s))
return op
|
519e0a46b954ea86ce366207ce8ffa9438bb842e | daniel-reich/ubiquitous-fiesta | /wvuk7d2mWgZEmFFYD_10.py | 130 | 3.609375 | 4 |
def shared_letters(txt1, txt2):
res = ""
for i in txt1:
if i in txt2 and not i in res:
res += i
return len(res)
|
c9e1c7631cf6d9ee042e4f49bc06983f51fc923b | daniel-reich/ubiquitous-fiesta | /kxrhqiE5so3AMXWS7_8.py | 152 | 3.515625 | 4 |
def get_number_of_apples(n, p):
apples = int(n * (100 - int(p[:-1])) / 100)
return "The children didn't get any apples" if not apples else apples
|
18df54532dc106b848fbd45bdaca8283c340ed9d | daniel-reich/ubiquitous-fiesta | /nHxBoXmRYq5vnoEnq_11.py | 169 | 3.5 | 4 |
def vowels(string):
a = string.count("a")
e = string.count("e")
i = string.count("i")
o = string.count("o")
u = string.count("u")
return a + e + i + o + u
|
e467d6a8fdb6233729dc10ede5c864d414cffddd | daniel-reich/ubiquitous-fiesta | /R7d5JE7NQCSnajuni_7.py | 375 | 3.515625 | 4 |
def convert_to_number(dictionary):
Revised = {}
Fronts = []
Backs = []
for key, value in dictionary.items():
Fronts.append(key)
Backs.append(value)
Counter = 0
Length = len(Fronts)
while (Counter < Length):
Key = str(Fronts[Counter])
Value = int(Backs[Counter])
Revised[Key] = Value
Counter += 1
return Revised
|
fee87fe1b0f4bea2b39ff71dff9cda9f1920b4e8 | daniel-reich/ubiquitous-fiesta | /763oGpb5JvctX5tAc_16.py | 389 | 3.640625 | 4 |
#edabit
#check anagrams
def is_anagram(text1, text2):
text1 = text1.lower()
text2 = text2.lower()
result = True
if len(text1) != len(text2):
result = False
else:
for t in text1:
if t not in text2:
result = False
break
return result
def main():
pass
if __name__ == "__main__":
main()
|
23e4c1658cbd832f04e1942edde636e26bb36fec | daniel-reich/ubiquitous-fiesta | /4AtqpqKdXAFofa566_20.py | 157 | 3.640625 | 4 |
def remove_leading_trailing(n):
n = n.lstrip("0")
if "." in n:
n = n.rstrip("0").rstrip(".")
if not n or n[0] == ".":
n = "0" + n
return n
|
ff8d9869324360c7c6d1c2827059fc264b867d67 | daniel-reich/ubiquitous-fiesta | /wyr9gCiBtFM7YLauK_2.py | 300 | 3.609375 | 4 |
def time_sum(times):
timelist = [ x.split(":") for x in times ]
seconds = sum([ int(x[2]) for x in timelist ])
minutes = sum([ int(x[1]) for x in timelist ]) + int(seconds/60)
hours = sum([ int(x[0]) for x in timelist ]) + int(minutes/60)
return [ hours , minutes % 60 , seconds % 60]
|
63edf24b3acd55eaea811a057a64121a683dfc60 | daniel-reich/ubiquitous-fiesta | /a6XHqehbttHnjE7bK_2.py | 80 | 3.515625 | 4 |
def is_repdigit(num):
num = str(num)
return num.count(num[0]) == len(num)
|
d3850025bca3f8b58c11dde727099c91ad6a0743 | daniel-reich/ubiquitous-fiesta | /nLNCPwzcbvrHmt4MF_16.py | 224 | 3.84375 | 4 |
def fibonacci_sequence():
fibbonacci = [0, 1]
total = 0
index = 1
while fibbonacci[-1] < 233:
total += fibbonacci[-1] + fibbonacci[-2]
fibbonacci.append(total)
total = 0
return fibbonacci
|
59f44b2f8aa6c225314055e1a4e4afa81cb28cb7 | daniel-reich/ubiquitous-fiesta | /vq3x6QP77d7Qwe8be_11.py | 524 | 3.8125 | 4 |
def odd_square_patch(lst):
for i in range(1,len(lst)+2):
if not has_patch(lst, i):
return i - 1
def has_patch(lst, n):
if n>len(lst) or n>len(lst[0]):
return False
for i in range(len(lst)-n+1):
for j in range(len(lst[0])-n+1):
if is_odd([[l for l in k[j:j+n]]for k in lst[i:i+n]]):
return True
return False
def is_odd(lst):
for i in lst:
for j in i:
if j % 2 != 1:
return False
return True
|
3556c75af7a86d5d4482b863ee529375ebc8ed33 | daniel-reich/ubiquitous-fiesta | /6sSWKcy8ttDTvkvsL_23.py | 344 | 3.703125 | 4 |
def after_n_days(days, n):
d = {"Monday" : 1, "Tuesday" : 2, "Wednesday" : 3, "Thursday" : 4,
"Friday" : 5, "Saturday" : 6, "Sunday" : 7
}
l = []
for day in days:
value = d.get(day)
value += n
while value > 7:
value = value - 7
for k, v in d.items():
if v == value:
l.append(k)
return l
|
a5c3bac4bf6f130b500c0ba081c1e44ada344051 | daniel-reich/ubiquitous-fiesta | /qGw8PGpMywu9PJti5_9.py | 373 | 3.875 | 4 |
def hanoi(n):
origin = 1
aux = 2
dest = 3
history = []
return towers_of_hanoi(n, origin, dest, aux, history)
def towers_of_hanoi(n, origin, dest, aux, history):
if n <= 0:
return history
towers_of_hanoi(n-1, origin, aux, dest, history)
history.append((origin, dest))
return towers_of_hanoi(n-1, aux, dest, origin, history)
|
cb9741f9947043c0a8d8644c6039d6a3ad86fbc2 | daniel-reich/ubiquitous-fiesta | /8gE6FCdnWbECiR7ze_11.py | 995 | 3.828125 | 4 |
def smith_type(number):
digitalroot = digsum(number)
digitalrootofSopf = digsum(sumofprim(number))
if digitalroot != digitalrootofSopf:
return "Not a Smith"
elif isprime(number):
return "Trivial Smith"
elif (digsum(number+1) == digsum(sumofprim(number+1))) and not isprime(number + 1):
return "Youngest Smith"
elif (digsum(number-1) == digsum(sumofprim(number-1))) and not isprime(number - 1):
return "Oldest Smith"
else:
return "Single Smith"
def digsum(num):
dignum = num
while len(str(dignum)) != 1:
dignum = sum(int(dignum) for dignum in str(dignum))
return dignum
def sumofprim(num):
div = 0
i = 2
while i*i <=num:
while (num % i) == 0:
div += i
num //= i
i+=1
if num > 1:
div += num
return div
def isprime(num):
if num > 1:
for i in range(2, num//2):
if (num % i) == 0:
return False
break
else:
return True
else:
return False
print(smith_type(6))
|
09d7cfbea5c2639fa72ebafc0978643f876bfd10 | daniel-reich/ubiquitous-fiesta | /5xPh4eEAtpMdXNoaH_1.py | 149 | 3.5 | 4 |
from collections import Counter
def longest_palindrome(s):
c = Counter(s)
return sum(l-l%2 for l in c.values()) + any(l%2 for l in c.values())
|
e9b085315ce79b9f4a79b55e9d3045bbb11df49f | daniel-reich/ubiquitous-fiesta | /stXWy2iufNhBo9sTW_18.py | 267 | 3.671875 | 4 |
import itertools
def valid_rondo(s):
if len(s) == 1:
return False
else:
if s[0] == 'A' and s[-1] == 'A':
for key,group in itertools.groupby(s):
if len(list(group)) > 1:
return False
return True
else:
return False
|
6cdaa797515c2f6b7d1e15bc5e2a7ea903d0d601 | daniel-reich/ubiquitous-fiesta | /AgGWvdPi56x5nriQW_7.py | 195 | 3.59375 | 4 |
def longest_slide(pyramid):
for r in range(len(pyramid)-2, -1, -1):
for c in range(len(pyramid[r])):
pyramid[r][c] += max(pyramid[r+1][c], pyramid[r+1][c+1])
return pyramid[0][0]
|
0d4df180cde0bee6bf47a965357e6b0e81e78c56 | daniel-reich/ubiquitous-fiesta | /Rn3g3hokznLu8ZtDP_21.py | 164 | 3.71875 | 4 |
def increment_string(txt):
if txt[-1].isdigit():
i = -1
while txt[i] == "9":
i -= 1
return txt[:i] + str(int(txt[i:]) + 1)
return txt + "1"
|
fac96256c55129b6a026438bda13cdd985696626 | daniel-reich/ubiquitous-fiesta | /iRvRtg2xxL9BnSEvf_10.py | 404 | 3.828125 | 4 |
class Person:
def __init__(self, name, love, hate):
self.name = name
self.love = love
self.hate = hate
def taste(self, food):
if food in self.love:
return "{} eats the {} and loves it!".format(self.name, food)
elif food in self.hate:
return "{} eats the {} and hates it!".format(self.name, food)
else:
return "{} eats the {}!".format(self.name, food)
|
7b502a5d6611f56fcf3f9d942e77225ef3bb782f | daniel-reich/ubiquitous-fiesta | /2t6NvMe27HtSmqC4F_5.py | 383 | 3.953125 | 4 |
def boolean_and(lst):
result = True
for element in lst:
result = result and element
return result
def boolean_or(lst):
result = False
for element in lst:
result = result or element
return result
def boolean_xor(lst):
result = lst[0]
for element in lst[1:]:
if result == element:
result = False
else:
result = True
return result
|
d9c03d8e4263d61c7dbe67264cc7be9d73dbdb25 | daniel-reich/ubiquitous-fiesta | /994QjWPmdhaR94DeF_17.py | 241 | 3.5625 | 4 |
def get_birthday_cake(name, age):
d = '#' if age % 2 == 0 else '*'
return [d * (22 + len(name) + len(str(age)) * 2), d + ' ' + str(age) + " Happy Birthday " + name + '! ' + str(age) + ' ' + d, d * (22 + len(name) + len(str(age)) * 2)]
|
192e9444df23ee2798ae6719e0fd3fa43a9f5db5 | daniel-reich/ubiquitous-fiesta | /Q72X3J8jq7SzSSXui_11.py | 205 | 3.5 | 4 |
def sentence_searcher(txt, word):
split_sentence = txt.split('.')
for eachsentence in split_sentence:
if word.lower() in eachsentence.lower():
return eachsentence.strip() + "."
return ''
|
d8aa81bc3b4c3018a148d889d963e49fd9c1856c | daniel-reich/ubiquitous-fiesta | /W73q9yML66xXbFfGY_7.py | 342 | 3.75 | 4 |
def coloured_triangle(row):
if len(row) == 1:
return row
newRow = ""
for i in range(1,len(row)):
if row[i-1] == row[i]:
newRow += row[i]
elif 'R' not in [row[i-1],row[i]]:
newRow += 'R'
elif 'G' not in [row[i-1],row[i]]:
newRow += 'G'
else:
newRow += 'B'
return coloured_triangle(newRow)
|
ec0dc199ad1f9699add1bc49023c922051eb49ca | daniel-reich/ubiquitous-fiesta | /Es985FEDzEQ2tkM75_4.py | 601 | 3.671875 | 4 |
def caesar_cipher(text, key):
RESULT = []
alphabet = "abcdefghijklmnopqrstuvwxyz"
print(len(alphabet))
for elem in list(str(text)):
if elem in list(alphabet):
POSITION = alphabet.find(elem)
key2 = alphabet.find(elem) + key
if key2 > 25:
key2 = key2 - 26
print(key2, RESULT, alphabet.find(elem) + key )
RESULT.append(list(alphabet)[key2])
else:
RESULT.append(' ')
print(''.join(RESULT))
return ''.join(RESULT)
caesar_cipher("iwxh xh p rwxetg", 11)
|
c4359b972d5e5518584bd9ee06d970f3c3f4b4d0 | daniel-reich/ubiquitous-fiesta | /BuwHwPvt92yw574zB_20.py | 150 | 3.890625 | 4 |
def list_of_multiples (num, length):
myList = []
for x in range(length):
multiple = (x+1) * num
myList.append(multiple)
return myList
|
96718dfc88f38b3728ea042615d85b4b1cadd1cb | daniel-reich/ubiquitous-fiesta | /vSo5XWNqKiBuN5zGr_4.py | 175 | 3.703125 | 4 |
def divide(x, y, res=0):
if abs(x) < abs(y):
return res if x * y >= 0 else -res
return divide(x - y, y, res + 1) if x * y > 0 else divide(x + y, y, res + 1)
|
4b60fa90b497154714aedb7029387a7678f161a2 | daniel-reich/ubiquitous-fiesta | /uojwbCn2yyqqk9Wpf_21.py | 329 | 3.671875 | 4 |
from math import sqrt
def is_untouchable(number):
l = []
for i in range(2,(number**2)+1):
if number==sum(divisors(i)): l.append(i)
return "Invalid Input" if number<2 else True if not l else l
def divisors(n):
divs = {1}
for i in range(2,int(sqrt(n))+1):
if n%i == 0: divs.update((i,n//i))
return divs
|
2b6d003adde3be5a42e0befe76f30cb650baabe3 | daniel-reich/ubiquitous-fiesta | /9Q5nsEy2E2apYHwX8_15.py | 301 | 3.5 | 4 |
class programmer:
def __init__ (self, salary, work_hours):
self.salary = salary
self.work_hours = work_hours
def __del__ (self):
return 'oof, {}, {}'.format(self.salary, self.work_hours)
def compare (self, other):
return self if self.salary < other.salary else other
|
2637947f94547908968a378b49da4513fe1e16a5 | daniel-reich/ubiquitous-fiesta | /vYYfFAAfjoc8crCqu_15.py | 384 | 3.5 | 4 |
def tree(h):
tree_lst=[]
tree=[]
width=(h*2)-1
h_count=1
for i in range(0,h):
# number of hashtags, starting at 1 - iterate +2
tree_lst.clear()
# white space each side = width - hashtags // 2
wsp=(width-h_count)//2
# add wsp + hashes + wsp to current str
#print(' '*wsp+('#'*h_count)+' '*wsp)
tree.append(' '*wsp+('#'*h_count)+' '*wsp)
h_count+=2
return tree
|
d33aafdb59be3bcfefc09c20e417dd6b558714d5 | daniel-reich/ubiquitous-fiesta | /A9iPfSEZ9fCrPQSwC_19.py | 227 | 3.625 | 4 |
import math
def points_in_circle(points, centerX, centerY, radius):
cnt=0
for x in range(0,len(points)):
if math.sqrt(pow((points[x]['x']-centerX),2)+pow((points[x]['y']-centerY),2))<radius:
cnt+=1
return cnt
|
7ee43eba437e3c69e59fa795d59d164c4f56ce3b | daniel-reich/ubiquitous-fiesta | /GuoJCiRJkr9CLRqJa_7.py | 108 | 3.5 | 4 |
def has_same_bread(lst1, lst2):
return True if lst1[0] == lst2[0] and lst1[-1] == lst2[-1] else False
|
2e9576fae1ea6f0a643bd9d87d1c747b652e63ce | daniel-reich/ubiquitous-fiesta | /9S8qp4XKG2qwQMdrb_3.py | 161 | 3.75 | 4 |
def ways_to_climb(h):
if h==0 or h==1:
return 1
if h==2:
return 2
else:
return ways_to_climb(h-1)+ways_to_climb(h-2)
|
139d6d70f1a571ed300cb45ee9d4ee2d5ab405d7 | daniel-reich/ubiquitous-fiesta | /9BJzrtpdMP8JFQg74_24.py | 232 | 3.59375 | 4 |
def twins(lst):
sum1 = sum2 = 0
for x in range(len(lst)):
for j in range(x+1):
sum1+=lst[j]
for i in range(x+1,len(lst)):
sum2+=lst[i]
if(sum1 == sum2):
return x+1
else:
sum1 = sum2 = 0
|
b2506145249814d3a8cfc8b2a13438527ac6c918 | daniel-reich/ubiquitous-fiesta | /vfuZia9ufckGzhGZh_13.py | 177 | 3.671875 | 4 |
def seq_level(lst):
if lst[2]-lst[1]==lst[1]-lst[0]: return "Linear"
if seq_level([a-b for a,b in zip(lst[1:],lst[:-1])]) == "Linear": return "Quadratic"
return "Cubic"
|
0d69720a8b87f97e981c9839118a0ffddfa7496f | daniel-reich/ubiquitous-fiesta | /994QjWPmdhaR94DeF_14.py | 303 | 3.609375 | 4 |
def get_birthday_cake(name, age):
if age % 2 != 0:
a = "*"+" "+str(age)+" "+"Happy Birthday "+ str(name)+"!"+" "+str(age)+" "+"*"
return ["*"*len(a),a,"*"*len(a)]
else:
a = "#"+" "+str(age)+" "+"Happy Birthday "+ str(name)+"!"+" "+str(age)+" "+"#"
return ["#"*len(a),a,"#"*len(a)]
|
a0bba106a0342f2b4bc1146a078f28548a156eb7 | daniel-reich/ubiquitous-fiesta | /ucsJxQNrkYnpzPaFj_15.py | 137 | 3.515625 | 4 |
def char_appears(sentence, char):
arr = sentence.lower().split()
ans = []
for el in arr: ans.append(el.count(char))
return ans
|
ddffafe1d433f534be4334d0e6a55a9c817f54d4 | daniel-reich/ubiquitous-fiesta | /2bTdN8sr3PQKkLHur_19.py | 88 | 3.71875 | 4 |
def divisible_by_b(a, b):
for i in range(b):
a+=1
if a%b==0:
return a
|
954f315640e1300bf618781e4e4e4f5bcda5ef96 | daniel-reich/ubiquitous-fiesta | /ojBNREQrg7EW9ZzYx_0.py | 307 | 3.75 | 4 |
import re
def count_eatable_chocolates(total_money, cost_of_one_chocolate):
m = int(re.findall(r'\d+', total_money)[0])
c = int(re.findall(r'-?\d+', cost_of_one_chocolate)[0])
if c<1: return 'Invalid Input'
ans = m//c
w = m//c
while w>2:
new = w//3
ans+=new
w-= 2*new
return ans
|
35c4f92e0ebcbe7b4c8e72943480a4c75b57d70a | daniel-reich/ubiquitous-fiesta | /yiEHCxMC9byCqEPNX_3.py | 177 | 4.03125 | 4 |
def is_palindrome(p):
if not p: return True
else: p = ''.join([x.lower() for x in p if x.isalpha()])
if p[0] == p[-1]:return is_palindrome(p[1:-1])
else: return False
|
09e7391ecc687b2eebfb522601df65d13397286e | daniel-reich/ubiquitous-fiesta | /kKFuf9hfo2qnu7pBe_17.py | 270 | 3.875 | 4 |
def is_prime(primes, num, left=0, right=None):
right = len(primes)-1
while right >= left:
guess = int((left+right)/2)
if primes[guess]==num:
return "yes"
if primes[guess]<num:
left = guess+1
else:
right = guess-1
return "no"
|
f0c145a3c5718e7318f278a843d133a1d3c624af | daniel-reich/ubiquitous-fiesta | /BDjhphREEa6Ds44Ty_12.py | 612 | 3.5625 | 4 |
def line_intersect(l1, l2):
m1, b1 = l1
m2, b2 = l2
x = (b2 - b1) / (m1 - m2)
return (round(x), round(m1 * x + b1))
def circles_intersect(c1, c2):
x1, y1, r1 = c1
x2, y2, r2 = c2
dy = (y2 - y1) or 0.000001
return ((x1 - x2)/dy, (r1**2 - x1**2 - y1**2 - r2**2 + x2**2 + y2**2) / (2 * dy))
def bomb(lst):
if lst[0][2] == 0: return (lst[0][0], lst[0][1])
if lst[1][2] == 0: return (lst[1][0], lst[1][1])
if lst[2][2] == 0: return (lst[2][0], lst[2][1])
for s in lst:
s[2] *= 0.343
return line_intersect(circles_intersect(lst[0], lst[1]), circles_intersect(lst[0], lst[2]))
|
c5117daee9c44c36ac43f9f8cba3ac5710765d7d | daniel-reich/ubiquitous-fiesta | /7AA54JmzruLMwG6do_7.py | 363 | 3.640625 | 4 |
def is_icecream_sandwich(txt):
if txt == "" or txt.count(txt[0]) == len(txt): return False
a = ""
for i in txt:
if i == txt[0]:
a += str(i)
else:
b = str(i)
break
res = [ele for ele in txt if(ele not in [txt[0], b])]
if txt.count(a) == 2 and not res:
return True
return False
|
3b9fb279ef2f0764d6196d653ad5ce2a28ee443f | daniel-reich/ubiquitous-fiesta | /vQgmyjcjMoMu9YGGW_4.py | 436 | 3.796875 | 4 |
def simplify(st):
from fractions import gcd
st = st.split('/')
numer = int(st[0]);denom = int(st[1])
common_divisor = gcd(numer, denom)
(reduced_num, reduced_den) = (int(numer / common_divisor), int(denom / common_divisor))
if reduced_den == 1:
return str(reduced_num)
elif common_divisor == 1:
return str(numer)+'/'+str(denom)
else:
return "%d/%d" % (reduced_num, reduced_den)
|
53f5dc7504008f6bfe1f8b10408d820a4f8415eb | daniel-reich/ubiquitous-fiesta | /YzZdaqcMsCmndxFcC_24.py | 169 | 3.59375 | 4 |
def centroid(x1, y1, x2, y2, x3, y3):
if ( (y2-y1)*(x3-x2) == (y3-y2)*(x2-x1)):
return False
return (round( ((x1+x2+x3)/3),2),round(((y1+y2+y3)/3),2))
|
6c10e70947da7cfd1c2125cc393d6c192d926eb2 | daniel-reich/ubiquitous-fiesta | /JBkfqYW4iYwmgvwTf_17.py | 112 | 3.78125 | 4 |
def is_prime(num):
return False if num == 1 \
else not sum( [ 1 for d in range(2,num) if not num%d ] )
|
b1c4a2e6b185bffe7df77535f114a955b94e94d5 | daniel-reich/ubiquitous-fiesta | /Erhk4BdRwd6J4MXH9_13.py | 104 | 3.59375 | 4 |
def is_leap(year):
return True if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0) else False
|
bd3e16f9384d838170d52c90f4a93b55d3203247 | daniel-reich/ubiquitous-fiesta | /J67xWvM4jFhn9nEpJ_1.py | 3,745 | 3.8125 | 4 |
def makeMagic(size):
#Determin what kind of Magic Square we are working with
return makeOddMagic(size) if (size%2) else makeSEvenMagic(size) if (size%4) else makeDEvenMagic(size)
#Make a Magic Square with an odd size
def makeOddMagic(size):
square = [[0 for i in range(size)] for j in range(size)] #Make empty Matrix
x, y = 0, size//2 #Starting index
for i in range(1, size**2 + 1):
square[abs(x)][y] = i
#Check for next index
if square[abs((x + 1)%-size)][(y + 1)%size] == 0:
x = (x + 1)%-size
y = (y + 1)%size
else:
x = (x - 1)%-size
return square # Return the finished Magic Square
#Make a Magic Square with a size divisible by 4
def makeDEvenMagic(size):
square = [[0 for i in range(size)] for j in range(size)] #Make empty Matrix
# Starting with the corners and the middle place the index value as at each location
cSize = size//4
# Top left
for i in range(0,cSize):
for j in range(0,cSize):
square[i][j] = (i)*size + j+1
# Top right
for i in range(0,cSize):
for j in range(size - cSize,size):
square[i][j] = (i)*size + j+1
# Bottom Left
for i in range(size - cSize,size):
for j in range(0,cSize):
square[i][j] = (i)*size + j+1
# Bottom right
for i in range(size - cSize,size):
for j in range(size - cSize,size):
square[i][j] = (i)*size + j+1
# Mid
for i in range(cSize, size - cSize ):
for j in range(cSize, size - cSize):
square[i][j] = (i)*size + j+1
# Next place the Backwards index as the value at each location that is still empty
for i in range(size):
for j in range(size):
if square[i][j] == 0:
square[i][j] = size**2 - ((i)*size + j)
return square # Return the finished Magic Square
#Make a Magic Square with an even size that is not divisible by 4
def makeSEvenMagic(size):
square = [[0 for i in range(size)] for j in range(size)] #Make empty Matrix
# Fill the corners with odd magic squares plus an offset
cSize = size//2
Temp = makeOddMagic(cSize)
# Top left
k = 0
offSet = 0
for i in range(0,cSize):
for j in range(0,cSize):
square[i][j] = Temp[k//cSize][k%cSize] + offSet
k += 1
# Bottom right
k = 0
offSet = cSize**2
for i in range(size - cSize,size):
for j in range(size - cSize,size):
square[i][j] = Temp[k//cSize][k%cSize] + offSet
k += 1
# Top right
k = 0
offSet = cSize**2*2
for i in range(0,cSize):
for j in range(size - cSize,size):
square[i][j] = Temp[k//cSize][k%cSize] + offSet
k += 1
# Bottom Left
k = 0
offSet = cSize**2*3
for i in range(size - cSize,size):
for j in range(0,cSize):
square[i][j] = Temp[k//cSize][k%cSize] + offSet
k += 1
# Make some swaps to correct the Magic square
dSize = cSize//2
#top half of swaps
for i in range(dSize):
for j in range(dSize):
temp1 = square[i][j]
square[i][j] = square[i + cSize][j]
square[i + cSize][j] = temp1
#mid swaps
i = dSize
for j in range(1, dSize+1):
temp1 = square[i][j]
square[i][j] = square[i + cSize][j]
square[i + cSize][j] = temp1
#top half of swaps
for i in range(dSize + 1, dSize*2+1):
for j in range(dSize):
temp1 = square[i][j]
square[i][j] = square[i + cSize][j]
square[i + cSize][j] = temp1
# If the size > 6 make some more swaps
dSize -= 1
for i in range(cSize):
for j in range(size - 1,size - dSize - 1, -1):
temp1 = square[i][j]
square[i][j] = square[i + cSize][j]
square[i + cSize][j] = temp1
return square # Return the finished Magic Square
|
63cb7c6164f30b56a37c6d01071dc6725953f97a | daniel-reich/ubiquitous-fiesta | /qGw8PGpMywu9PJti5_8.py | 312 | 4.03125 | 4 |
def hanoi(n,start = 1,middle = 2,end = 3,ans = None):
if ans == None:
ans = []
if n == 0:
return []
if n == 1:
ans += [(start,end)]
else:
hanoi(n-1,start,end,middle,ans)
ans += [(start,end)]
hanoi(n-1,middle,start,end,ans)
return ans
|
cc5485e25c5a3088f9faac0dfb46b213c6d318f5 | daniel-reich/ubiquitous-fiesta | /uPAmqwiHmvwpwoBom_10.py | 974 | 3.828125 | 4 |
def convert_to_roman(num):
ans=[]
while num>0:
if num>999:
ans.append("M")
num-=1000
continue
elif num>899:
ans.append("CM")
num-=900
continue
elif num>499:
ans.append("D")
num-=500
continue
elif num>399:
ans.append("CD")
num-=400
continue
elif num>99:
ans.append("C")
num-=100
continue
elif num > 89:
ans.append("XC")
num-=90
continue
elif num>49:
ans.append("L")
num-=50
continue
elif num>39:
ans.append("XL")
num-=40
continue
elif num>9:
ans.append("X")
num-=10
continue
elif num>8:
ans.append("IX")
num-=9
continue
elif num>4:
ans.append("V")
num-=5
continue
elif num>3:
ans.append("IV")
num-=4
continue
elif num>0:
ans.append("I")
num-=1
continue
return ''.join(ans)
|
517ee0f62362773ad5310e34429c4813a9365b32 | daniel-reich/ubiquitous-fiesta | /ik9CtowAndmAiStze_9.py | 132 | 3.59375 | 4 |
def frequency_sort(s):
lst={ x:(-s.count(x), x==x.lower(),x ) for x in set(s) }
return ''.join(sorted(s,key=lambda x:lst[x]))
|
bcc96e01c92ef6e122170019c36da72e8d7417ac | daniel-reich/ubiquitous-fiesta | /AeWbFdxSwAf5nhQpG_10.py | 172 | 3.5 | 4 |
def aux(num):
if not int(num/10):
return num%10
return num%10*aux(int(num/10))
def persistence(num):
return 1+persistence(aux(num)) if int(num / 10) else 0
|
60775d16bf4c01b53f00cdd5ffe0a6f2d78fb741 | daniel-reich/ubiquitous-fiesta | /2jcxK7gpn6Z474kjz_17.py | 461 | 3.546875 | 4 |
# SOLUTION WITHOUT REGEX!!!
def security(txt):
a, x, T, G, S = [], [], [], [], []
for i in txt:
if i != "x": a.append(i)
for i in range(len(a)):
if a[i]=="T": T.append(i)
elif a[i]=="G": G.append(i)
elif a[i]=="$": S.append(i)
if len(T) == 0 or len(S)==0: return "Safe"
for i in T:
for j in S:
if abs(i-j) == 1: return "ALARM!"
return "Safe"
|
dd3d551939a57738aa83effaa2a5d7bfedcac1e8 | daniel-reich/ubiquitous-fiesta | /bGRYmEZvzWFK2sbek_7.py | 133 | 3.640625 | 4 |
def get_missing_letters(s):
alpha='abcdefghijklmnopqrstuvwxyz'
t=''
for x in alpha:
if x not in s:
t+=x
return t
|
5f519a28d703f374716a905f4e105c3e11168ee0 | daniel-reich/ubiquitous-fiesta | /AdJNWPbfL9LunsNh9_2.py | 233 | 3.71875 | 4 |
def multiplication_table(n):
if n == 1:
return [[1]]
temp = [x for x in range(1, n+1)]
arr_res = [temp]
for _ in range(n-1):
temp = [x+j+1 for j, x in enumerate(temp)]
arr_res.append(temp)
return arr_res
|
241be2738e83bc13efa706eb8bea435f772faa91 | daniel-reich/ubiquitous-fiesta | /eAnhzXPeGbobqk2P2_13.py | 137 | 3.65625 | 4 |
def century(year):
import math
c=(year-1)//100+1
if c==21:
return "21st century"
else:
return "{}th century".format(c)
|
e304e66e0b8c36dd0045f16c1c9032325ef20dda | daniel-reich/ubiquitous-fiesta | /q5jCspdCvmSjKE9HZ_17.py | 190 | 3.734375 | 4 |
from fractions import gcd
def lcm_of_list(numbers):
lcm = numbers[0]
for i in range(1, len(numbers)):
lcm = lcm * numbers[i] // gcd(lcm, numbers[i])
return lcm
|
3a654f81004bdba00182775809efc6f48104a149 | daniel-reich/ubiquitous-fiesta | /GWBvmSJdciGAksuwS_4.py | 75 | 3.5 | 4 |
def find_letters(word):
return [l for l in word if word.count(l) == 1]
|
c7bbf4c3de3a182b0f6455711675a4de7eec96b1 | daniel-reich/ubiquitous-fiesta | /Sf7iS6JhA7nadm6CR_4.py | 782 | 3.515625 | 4 |
class Divisibility_rule:
ten_by_13 = [1, 10, 9, 12, 3, 4]
def __init__(self, start):
self.s = [start]
def advance(self):
number = list(reversed(str(self.s[-1])))
nn = []
index = 0
for n in range(len(number)):
try:
nn.append(int(number[n]) * Divisibility_rule.ten_by_13[n])
except IndexError:
nn.append(int(number[n]) * Divisibility_rule.ten_by_13[index])
index += 1
if index >= len(Divisibility_rule.ten_by_13):
index = 0
# print(index, int(number[n]), n, number, nn)
# print(sum(nn), self.s)
self.s.append(sum(nn))
def divisibility_rule(n):
dr = Divisibility_rule(n)
while len(list(set(dr.s))) == len(dr.s):
dr.advance()
return dr.s[-1]
|
0535bd5d154b88315212f853c4992c125466ab07 | daniel-reich/ubiquitous-fiesta | /ya4diBApyLQKG7TQK_24.py | 265 | 3.578125 | 4 |
def validate_relationships(txt):
op=''.join(i if i in '><=' else ' ' for i in txt).split()
for i in range(len(op)):
if op[i]=='=':
op[i]='=='
txt=''.join(i if i not in '><=' else ' ' for i in txt).split()
return eval('{}'.join(txt).format(*op))
|
b54a7fb272cde259a1e36c64be4a67537cdd77db | daniel-reich/ubiquitous-fiesta | /3ucrYGBkvJwjbFL4G_10.py | 198 | 3.609375 | 4 |
def reversible_inclusive_list(s, e):
if s == e:
return [s]
elif s < e:
return [s] + reversible_inclusive_list(s + 1, e)
else:
return [s] + reversible_inclusive_list(s - 1, e)
|
09e9d6c4d2d444db607ad3a639c4c2e5c83af1d7 | daniel-reich/ubiquitous-fiesta | /8gE6FCdnWbECiR7ze_15.py | 1,482 | 3.703125 | 4 |
from sys import stdout
def isprime(num):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
return False
break
else:
return True
else:
return False
def factors(n):
rt = []
f = 2
if n == 1:
rt.append(1);
else:
while 1:
if 0 == ( n % f ):
rt.append(f);
n //= f
if n == 1:
return rt
else:
f += 1
return rt
def sum_digits(n):
sum = 0
while n > 0:
m = n % 10
sum += m
n -= m
n //= 10
return sum
def add_all_digits(lst):
sum = 0
for i in range (len(lst)):
sum += sum_digits(lst[i])
return sum
def smith_type(number):
if number==1:
return "Not a Smith"
if sum_digits(number-2)==add_all_digits(factors(number-2))and sum_digits(number-1)==add_all_digits(factors(number-1)) and sum_digits(number)==add_all_digits(factors(number)):
return "Oldest Smith"
if isprime(number):
return "Trivial Smith"
if sum_digits(number)==add_all_digits(factors(number))and sum_digits(number-1)==add_all_digits(factors(number-1)):
return "Youngest Smith"
if sum_digits(number)==add_all_digits(factors(number)):
return "Single Smith"
if sum_digits(number)!=add_all_digits(factors(number)):
return "Not a Smith"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.