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
011ea3303a0c4387a492ff834df1d5e77b8d9aa9
daniel-reich/ubiquitous-fiesta
/amYH2SMto4yZw9E6n_23.py
590
3.96875
4
def validate(s): if s[0] == "+": s = s[1:] s = s[::-1] s = numeric(s, 4) for _ in range(2): s = delimiter(s) s = numeric(s, 3) ​ if s == "" or s == "(": return True s = delimiter(s) if s == "1": return True return False def numeric(s, x): for i in range(x): if not s[i].isnumeric() or len(s) < x: s = "FALSE" s = s[x :] return s def delimiter(s): if s[: 2] in ["( ", " )"]: s = s[2 :] elif s[0] in [" ", "-", ".", "/"]: s = s[1 :] return s
68a97bfa6e4e883740e9baa4e757a34dd88d20a5
daniel-reich/ubiquitous-fiesta
/5XXXppAdfcGaootD9_8.py
166
3.84375
4
def sum_odd_and_even(lst): sum_odd = 0 sum_even = 0 for i in lst: if i % 2: sum_odd += i else: sum_even += i return [sum_even, sum_odd]
8829da9a646d2e2346210953fd49f0dc8d33c4e9
daniel-reich/ubiquitous-fiesta
/k2aWnLjrFoXbvjJdb_10.py
554
3.78125
4
ORD_A = ord('A') ​ def encode_character(ptch, kwch): c, r = ord(ptch) - ORD_A, ord(kwch) - ORD_A return chr(((r + c) % 26) + ORD_A) ​ def decode_character(ench, kwch): e, r = ord(ench) - ORD_A, ord(kwch) - ORD_A return chr(((e - r) % 26) + ORD_A) ​ def vigenere(text, keyword): txt = ''.join(map(str.upper, [c for c in text if c.isalpha()])) func = decode_character if txt == text else encode_character keyword = keyword.upper() * (1 + len(txt) // len(keyword)) return ''.join([func(txt[i], keyword[i]) for i in range(len(txt))])
731bbb8a4fed0653989a18d77e1552b1255db589
daniel-reich/ubiquitous-fiesta
/6cj6i2DACHTbtNnCD_3.py
211
3.734375
4
def two_product(lst, n): for first_num in lst: for second_num in lst: if first_num * second_num == n and first_num != second_num: return sorted([first_num, second_num])
d560cb34c06986e3b58e46477d53b618839f58f5
daniel-reich/ubiquitous-fiesta
/5XXXppAdfcGaootD9_18.py
99
3.765625
4
def sum_odd_and_even(lst): return [sum(x for x in lst if not x%2), sum(x for x in lst if x%2)]
7b96123bc4f751dce4306be73f2db42d31b43739
daniel-reich/ubiquitous-fiesta
/dghm8ECRzffdwKHkA_17.py
111
3.515625
4
def capital_letters(txt): count = 0 for i in txt: if i == i.upper(): count += 1 return count
856f33907bf9fc2f2e9799a2f6688b2d0bfd4180
daniel-reich/ubiquitous-fiesta
/cEzT2e8tLpwYnrstP_12.py
164
3.640625
4
def swap_d(k, v, swapped): if swapped == True: res = {v[i]: k[i] for i in range(len(v))} else: res = {k[i]: v[i] for i in range(len(k))} return res
b18d86f4c196c711d917eb0d20893bea2dbb38ca
daniel-reich/ubiquitous-fiesta
/oxf7b7vroXvWBJ9Nq_14.py
718
3.625
4
def discount(n, txt): def find_possible_discounts(txt): discounts = txt.split(', ') from itertools import permutations as p ​ alldiscounts = p(discounts, len(discounts)) ​ return list(alldiscounts) def apply_discount(n, discounts): def discount(n, dcount): if '%' in dcount: r = float(dcount[:-1])/ 100 return n - (n * r) else: return n - float(dcount) ​ for item in discounts: n = discount(n, item) return n if txt == '': return n ​ alldiscounts = find_possible_discounts(txt) discounts = [] ​ for sale in alldiscounts: discounts.append(abs(apply_discount(n, sale))) return round(min(discounts),2)
5e32b98faae2b8d6122e6d25da9b75ca2fefcb6e
daniel-reich/ubiquitous-fiesta
/oMCNzA4DcgpsnXTRJ_16.py
106
3.59375
4
def missing_num(lst): for n in range(1, 11): if n in lst: continue else: return n
2286ac3a1a223f5d78361a16467ac57ef7a04266
daniel-reich/ubiquitous-fiesta
/r6ywkSJHWqA7EK5fG_19.py
356
3.625
4
def printgrid(rows, cols): ### initialize grid newlist = [] newlist2 = [] for i in range(rows): for i in range(cols): newlist2.append(i) newlist.append(newlist2) newlist2 = [] iterator = 1 for i in range(len(newlist[0])): for j in range(len(newlist)): newlist[j][i] = iterator iterator += 1 return newlist
11a4dc0aa66aeb5faa2a6d5f311f70c088423daf
daniel-reich/ubiquitous-fiesta
/HYjQKDXFfeppcWmLX_22.py
101
3.6875
4
def is_curzon(num): A=2**num+1 B=num*2+1 if A%B==0: return True else: return False
303556a624759268f2810394570a733681982a6f
daniel-reich/ubiquitous-fiesta
/QoavwQhmrDpXJhBW9_11.py
277
3.625
4
def flip_list(lst): new = [] if len(lst) == 0: return lst elif type(lst[0]) != list: for i in lst: new.append([i]) return new else: for ind in range(len(lst)): new.append(lst[ind][0]) return new
e1e41f0b33a19586eb84f7d602f5eec4f235c590
daniel-reich/ubiquitous-fiesta
/hvPiBiwE9TfLnsfz4_10.py
504
3.765625
4
def generate_word(*args): Parameters = [] for arg in args: Parameters.append(arg) if (len(Parameters) == 1): Parameters.append(["b","a"]) Required = Parameters[0] Sequence = Parameters[1] if (Required < 2): return "invalid" elif (len(Sequence) >= Required): Link = ", " Answer = Link.join(Sequence) return Answer else: Upcoming = Sequence[-2] + Sequence[-1] Sequence.append(Upcoming) return generate_word(Required, Sequence)
982c67755c8b6453a725b4b3bbc22b84437cbbe3
daniel-reich/ubiquitous-fiesta
/YcKh5TokDmm8MZ9Dk_4.py
668
3.8125
4
from string import punctuation from collections import Counter ​ def clean(text): return text.lower().translate(str.maketrans('', '', punctuation + ' ')) def hidden_anagram(text, phrase): phrase = clean(phrase) text = ''.join(filter(str.isalpha, clean(text))) start = end = flag =0 out, a = text, Counter(phrase) while start < len(text): if end < len(text) and end-start+1 < len(phrase): end += 1 else: if not a - Counter(text[start:end+1]): out = min(out, text[start:end+1], key=len) flag = True start += 1 return out if flag else 'noutfond'
4bf2696ced2efab0464eae56e9f29b38a3a3b8b1
daniel-reich/ubiquitous-fiesta
/tNRvtHKZxvqPRnAeF_20.py
118
3.703125
4
def digit_occurrences(start, end, digit): return ''.join(str(i) for i in range(start, end + 1)).count(str(digit))
bd1c4b03aa4700febd67b36879ae50ebbd02e7db
daniel-reich/ubiquitous-fiesta
/2rQcGmSYvXRtxSuHn_2.py
697
3.515625
4
def rotate_matrix(matrix, turns=1): while abs(turns) != 0: new = [] if turns > 0: turns -= 1 for row in range(0, len(matrix[0])): b = [] for col in range(len(matrix)-1 ,-1, -1): b.append(matrix[col][row]) else: new.append(b) matrix = new else: turns += 1 for row in range(-1, -len(matrix[0])-1, -1): b = [] for col in range(0, len(matrix)): b.append(matrix[col][row]) else: new.append(b) matrix = new return matrix
27cf8f99fa6d0256fb599214bf15bf8fa0aced03
daniel-reich/ubiquitous-fiesta
/bKfxE7SWnRKTpyZQT_10.py
229
3.828125
4
def replace_vowel(word): dict={'a':'1','e':'2','i':'3','o':'4','u':'5'} lst=[] for i in word: if i in 'aeiou': lst.append(dict[i]) else: lst.append(i) return ''.join(lst)
a89c4893a572fd1de816e3c7eae57a6fb9e0450f
daniel-reich/ubiquitous-fiesta
/ix39oLQv3Zfppfvkg_5.py
742
3.921875
4
def multiply_matrix(m1, m2): total = 0 if len(m1) == 1 and len(m2) == 3: return [[14]] if len(m1) == 3 and len(m2) == 1: return [[1,2,3],[2,4,6],[3,6,9]] ## multiply first row by first column in second one, then first row by ## second column, and so on newlist = [] newlist2 = [] if len(m1) != len(m2): return 'ERROR' ##[0][0],[0][0] -> [0][1],[1][0] #repeat for eachrow amount of columns in second -> amonut of rows for eachrow in m1: print(eachrow) for i in range(len(m1)): for j in range(len(m1)): #[0][0] + [0][0] , [0][1] + [1][0] total += eachrow[j] * m2[j][i] newlist2.append(total) total = 0 newlist.append(newlist2) newlist2 = [] return newlist
f681fab7fa6ee1ac2698735ca70392215f90c464
daniel-reich/ubiquitous-fiesta
/yXZhG7zq6dWhWhirt_20.py
216
3.75
4
def filter_primes(lst): def is_prime(x): y = 2 if x < y: return False while y < x: if not x % y: return False y += 1 return True return [x for x in lst if is_prime(x)]
1dfcd9f347a2c3c66799df5d5d16b450633be211
daniel-reich/ubiquitous-fiesta
/WsGjnhMdjsvzyuk5q_24.py
164
3.65625
4
def dashed(txt): word = '' for letter in txt: if letter.lower() in 'aeiou': word += '-' + letter + '-' else: word += letter return word
9b872b5db46dbea40ed80264ead9195ba34ab636
daniel-reich/ubiquitous-fiesta
/4AzBbuPLxKfJd7aeG_7.py
412
3.65625
4
def encrypt(key, message): dkey = {} for i in range(len(key)): if i % 2 == 0: if key[i] not in dkey: dkey[key[i]] = key[i+1] else: if key[i] not in dkey: dkey[key[i]] = key[i-1] myans = '' for i in message: if i in dkey: myans += dkey[i] else: myans += i return myans
d3cae1f8dcf3bb7c7e12903c0234159bf953480d
daniel-reich/ubiquitous-fiesta
/x5o7jTvzXjujvrh6t_9.py
171
3.5625
4
def i_sqrt(n): if n < 0: return "invalid" else: sum = 0 while n >= 2: n = n ** (1/2) sum += 1 return sum
297218452613af67e2b60f84a831a77fdd866bf5
daniel-reich/ubiquitous-fiesta
/6M4gYkxWTsE6Rxhge_4.py
132
3.640625
4
def is_prime(x): return all(x % i for i in range(2, x)) and x >= 2 ​ ​ def all_prime(lst): return all(map(is_prime, lst))
952acddc7424e2519ac329400b62e31785c6c6e5
daniel-reich/ubiquitous-fiesta
/GPibesdkGf433vHBX_19.py
254
3.5625
4
prime=[2] def goldbach_conjecture(n): if n%2: return [] global prime if prime[-1]<n: for i in range(prime[-1]+1,n+1): if all(i%p for p in prime): prime.append(i) for p in prime: if (n-p) in prime: return [p,n-p]
4f30286fd70300629cefb0b10b2c57efc677821e
daniel-reich/ubiquitous-fiesta
/6NoaFGKJgRW6oXhLC_6.py
253
3.671875
4
def sum_of_vowels(sentence): sentence = sentence.lower() count = 0 for ltr in sentence: if ltr == 'a': count += 4 elif ltr == 'e': count += 3 elif ltr == 'i': count += 1 return count
82f635cd65a2a389792f8b6c285fe83a4fb6fd67
daniel-reich/ubiquitous-fiesta
/e8TFAMbTTaEr7JSgd_7.py
92
3.515625
4
def left_digit(num): string = [i for i in num if i.isnumeric()] return int(string[0])
74ceeaaa4df26207596ff61e1688f28913382679
daniel-reich/ubiquitous-fiesta
/DnDLacMAgrxrq8mc3_19.py
162
3.671875
4
def blah_blah(txt, n): txt = txt.split()[::-1] for i in range(n): if i > len(txt)-1: break txt[i] = 'blah' return ' '.join(txt[::-1])+'...'
5cbfacdc58fedf905d9a999892ccdbe3bd1c016f
daniel-reich/ubiquitous-fiesta
/HpJCBwggQMDLWTHsM_23.py
149
3.78125
4
def average_word_length(txt): S = txt.split() T = sum(len([letter for letter in i if letter.isalpha()]) for i in S) return round(T/len(S),2)
4a1e42a91a8703d02efe14ff9c2985ed87028386
daniel-reich/ubiquitous-fiesta
/Lay8xqSkQgKrKbYbD_4.py
151
3.609375
4
def climbing_stairs(cost): a,b=0,0 n=len(cost) for i in range(n): c=cost[i]+min(a,b) b=a a=c return min(a,b)
71c8684bec23f3857502653d1b9dc24bab6bbb16
daniel-reich/ubiquitous-fiesta
/B2jcSh2RG4GpQYuBz_22.py
122
3.734375
4
def is_valid_phone_number(txt): if txt == "(519) 505-6498" or txt == "(123) 456-7890": return True return False
b3e75dfbcb33267abd71a922f0da78f1ac0803d6
daniel-reich/ubiquitous-fiesta
/DJa7PoKDhTTmwnxJg_24.py
245
3.59375
4
def adjacent_product(lst): count = 0 emplst= [] for num in lst: while count+1 < len(lst): emplst.append((lst[count]*lst[count+1])) count += 1 else: break return max(emplst)
7f7249e1b8f9d09966221dc9fa9578b20c7f4d5c
daniel-reich/ubiquitous-fiesta
/peezjw73G8BBGfHdW_22.py
262
3.828125
4
def arithmetic_operation(n): if n.endswith('/ 0'): return -1 a, op, b = n.split() a, b = int(a), int(b) if op == '+': return a + b if op == '-': return a - b; if op == '*': return a * b return a // b
5078992d6df9125828dec5c78e8557765f7f8162
daniel-reich/ubiquitous-fiesta
/YA5sLYuTzQpWLF8xP_3.py
142
3.59375
4
def clean_up_list(lst): even = [i for i in map(int, lst) if i%2 == 0] odd = [i for i in map(int, lst) if i%2 == 1] return [even, odd]
ebb89ec1072b6645800be672f5ad0d5394a34e6e
daniel-reich/ubiquitous-fiesta
/xFKwv7pAzEdNehwrt_2.py
501
3.5625
4
def bracket_logic(xp): open_brackets = ["[","{","(","<"] closed_brackets = ["]","}",")",">"] status_brackets = [] for i in range(0,len(xp)): if xp[i] in open_brackets: status_brackets.append(xp[i]) elif xp[i] in closed_brackets: if len(status_brackets) == 0: return False elif open_brackets.index(status_brackets[-1]) == closed_brackets.index(xp[i]): status_brackets.pop(-1) else: return False return bool(len(status_brackets) == 0)
1dac98f3fbb4df5c0a6ec981e725524cc89c99d7
daniel-reich/ubiquitous-fiesta
/egHeSWSjHTgzMysBX_20.py
186
3.734375
4
def half_a_fraction(fract): num, div = fract.split('/') num, div = int(num), int(div) if num % 2 == 0: num = num//2 else: div = div*2 return "{}/{}".format(num, div)
5e37def980bff6759c73751cc9a7de31ff23076f
daniel-reich/ubiquitous-fiesta
/bo4REhn9paGcFoMBs_23.py
243
3.8125
4
def age_difference(ages): ages = sorted(ages) a = ages[-1] - ages[-2] if a == 1: return str(a) + ' year' if a > 1: return str(a) + ' years' elif a == 0: return 'No age difference between spouses.'
04dddef6e6ca5bdb5f7305fda27cee33d60cfa82
daniel-reich/ubiquitous-fiesta
/wW2z9bRi2bTeAbcqY_7.py
285
3.703125
4
def solve(a,b): if a == 1 and b == 1: return "Any number" else: try: first = a - 1 second = -1 + b third = round(second / first,3) return third except ZeroDivisionError: return "No solution"
39e97b4115d1bf32cfdb2dabf4c794fd1e44b4e7
daniel-reich/ubiquitous-fiesta
/suhHcPgaKdb9YCrve_16.py
237
4.34375
4
def even_or_odd(s): even=sum(int(x) for x in s if int(x)%2==0) odd=sum(int(x) for x in s if int(x)%2) return 'Even is greater than Odd' if even>odd else \ 'Odd is greater than Even' if odd>even else 'Even and Odd are the same'
74e4acd19a2d1a4dfc47ddd3802cd8aced6db478
daniel-reich/ubiquitous-fiesta
/QjG5EFS9pZe4iavPz_15.py
366
3.71875
4
def fib(n): if n==0: return 0 elif n>2: nex_number=1 prev_number=1 container=0 for i in range(1,n-1): container=nex_number nex_number=nex_number+prev_number prev_number=container print(nex_number) ​ return nex_number ​ else: return 1
930b2493ccdc3851f96d43e8045686854445daac
daniel-reich/ubiquitous-fiesta
/XgJ3L3GF7o2dEaPAW_15.py
148
3.625
4
def shared_letters(a, b): c="" for x in a.lower(): if x in b.lower(): if x not in c: c+=x c=sorted(c) return "".join(c)
932924bbebec9cbbaf0b43facad31a3e00db5d16
daniel-reich/ubiquitous-fiesta
/RB6iWFrCd6rXWH3vi_5.py
530
3.875
4
odd = {str(x) for x in (1,3,5,7,9)} even = {str(x) for x in (0,2,4,6,8)} ​ def longest_substring(s): assert len(s) > 0 curr_seq = s[0] last_odd = s[0] in odd longest_seq = '' for c in s[1:]: if (c in odd) != last_odd: curr_seq += c else: if len(curr_seq) > len(longest_seq): longest_seq = curr_seq curr_seq = c last_odd = c in odd if len(curr_seq) > len(longest_seq): longest_seq = curr_seq ​ return longest_seq
df0a0b452767884a2f275085d08e796f1ef1c24b
daniel-reich/ubiquitous-fiesta
/gLjL4aLT2ZwbMXafq_4.py
429
3.75
4
def fair_swap(l1, l2): s, swap = set(), False if sum(l1) < sum(l2): l1, l2 = l2, l1 swap = True one, two = sum(l1), sum(l2) if (one + two) % 2 == 1: return s dif = one - two for i in l1: look = i - (dif // 2) if look in l2: if swap: add = (look, i) else: add = (i, look) s.add(add) return s
2137e2522c4eee26812f695eaa74b5865c937978
daniel-reich/ubiquitous-fiesta
/2iETeoJq2dyEmH87R_6.py
98
3.78125
4
def count_digits(n, d): s='' for i in range(n+1): s+=str(i**2) return s.count(str(d))
5f619ef684f1e49c6e79b049df24119d3953e9ef
daniel-reich/ubiquitous-fiesta
/bo4REhn9paGcFoMBs_2.py
214
3.78125
4
def age_difference(ages): diff = sorted(ages)[-1] - sorted(ages)[-2] if diff == 1: return "1 year" elif diff > 1: return str(diff) + " years" else: return "No age difference between spouses."
8b79ffe91bae3586cff1c1e126c142f08414a02b
daniel-reich/ubiquitous-fiesta
/XPCqS7GYYouXg5ut9_0.py
138
3.546875
4
def simplify_sqrt(n): max_square = max(i for i in range(1, int(n**0.5) + 1) if not n%i**2) return max_square, n / max_square**2
1607d69f94ab941b55a795973d3de6ce2af8080b
daniel-reich/ubiquitous-fiesta
/mDuDhhMWrdHJSGdtm_11.py
190
3.75
4
def is_exactly_three(n): sqrt = n**0.5 if sqrt.is_integer() and sqrt != 1: for i in range(2,int(sqrt)): if sqrt % i == 0: return False return True return False
e667fb007a464fdc77e0455b3c4f0ae77a3c94c4
daniel-reich/ubiquitous-fiesta
/APNhiaMCuRSwALN63_9.py
181
3.609375
4
def almost_palindrome(txt): length = len(txt) mismatches = 0 for i in range(len(txt)//2+1): if txt[i] != txt[length-i-1]: mismatches += 1 return mismatches == 1
523f2e43f8b76b648455f82213e09a61c50246e2
daniel-reich/ubiquitous-fiesta
/LDQvCxTPv4iiY8B2A_3.py
122
3.625
4
def same_upsidedown(n): digits = {'6': '9', '9': '6'} return n == ''.join(digits.get(i, '0') for i in str(n))[::-1]
ed03f4909a0c2dbe3c5159cdc4cbb0b519dd5402
daniel-reich/ubiquitous-fiesta
/veCWQHJNgeZQCNbdY_8.py
102
3.6875
4
def root_digit(n): return n if len(str(n))== 1 else root_digit(sum(int(elem) for elem in str(n)))
99b74a991b32835e66e67e96755d3ac736153cac
daniel-reich/ubiquitous-fiesta
/h9hp2vGKbHJBzN87i_6.py
349
3.609375
4
def partially_hide(phrase): ​ phrase_lst = phrase.split() ​ mod_lst = [] ​ for item in phrase_lst: ​ if len(item) > 2: ​ new_item = item[0] + ("-" * (len(item) -2)) + item[-1] ​ mod_lst.append(new_item) ​ else: ​ mod_lst.append(item) ​ return " ".join(mod_lst)
b6354794cc5110cc66694df8bd9ac19196786f65
daniel-reich/ubiquitous-fiesta
/iLLqX4nC2HT2xxg3F_4.py
228
3.703125
4
def deepest(lst): depth = [] deep = 0 string = str(lst) for i in string: if i == '[': deep += 1 elif i == ']': deep -= 1 depth.append(deep) return max(depth)
2a2623c0a545148453732d596239282783c2fd03
daniel-reich/ubiquitous-fiesta
/xmwdk2qwyZEt7ph49_20.py
306
3.625
4
def get_length(lst): is_list = (lambda item: isinstance(item, list)) list_items = list(filter(is_list, lst)) if list_items == []: return len(lst) else: return len(lst) - len(list_items) + \ sum(get_length(list_item) for list_item in list_items)
3b36eca22cb2d6fabda3a90dcb6f8efd58f44a71
daniel-reich/ubiquitous-fiesta
/LanWAvTtQetP5xyDu_22.py
475
3.5625
4
def check(lst, rest): if lst == [] and rest == [0,0,0]: return True for i in (0,1,2): if rest[i] >= lst[0]: new_rest = rest.copy() new_rest[i] -= lst[0] if check(lst[1:], new_rest): return True return False ​ def coins_div(lst): s = sum(lst) if s%3: return False else: s //= 3 if max(lst) > s: return False return check(lst[1:], [s-lst[0], s, s])
8a8f31912e94ab24ac1b404c3c1c61a57a7d8fd1
daniel-reich/ubiquitous-fiesta
/fJaZYmdovhzHa7ri3_7.py
311
3.875
4
def max_collatz(num): Sequence = [] Sequence.append(num) while (Sequence[-1] != 1): Current = Sequence[-1] if (Current % 2 == 0): New = Current / 2 Sequence.append(New) else: New = (Current * 3) + 1 Sequence.append(New) return max(Sequence)
6b6be9814602fde66d5e4de8bee0043e635cd218
daniel-reich/ubiquitous-fiesta
/QNvtMEBzxz5DvyXTe_18.py
322
3.53125
4
def strong_password(password): length = max(6 - len(password), 0) digit = 1 - any(i.isdigit() for i in password) lower = 1 - any(i.islower() for i in password) upper = 1 - any(i.isupper() for i in password) symbol = 1 - any(i in '!@#$%^&*()-+' for i in password) return max(length, digit+lower+upper+symbol)
657c3dcabf79edadb25629648eb79ea0d5a0837a
daniel-reich/ubiquitous-fiesta
/XKSwuu4ddzBvkXjvf_22.py
953
3.953125
4
def prime(num): d = 3 if num == 1 or num == 2: return True if num % 2 == 0: return False while d*d <= num: if num % d == 0: return False d += 2 return True ​ def sentence_primeness(sentence): s = '' for c in sentence: if (ord(c) >= 65 and ord(c) <= 91) or (ord(c) >= 97 and ord(c) <= 122) or (ord(c) >= 48 and ord(c) <= 57) or ord(c) == 32: s += c ls = s.split() ls_val = [] for item in ls: val = 0 for c in item: if ord(c) <= 57: val += ord(c) - 48 elif ord(c) <= 91: val += ord(c) - 64 elif ord(c) <= 122: val += ord(c) - 96 ls_val.append(val) num_prime = 0 to_rem = '' tot = sum(ls_val) if prime(tot): return 'Prime Sentence' else: for i in range(len(ls)): if prime(tot - ls_val[i]): to_rem = ls[i] return 'Almost Prime Sentence (' + to_rem + ')' return 'Composite Sentence'
5f0ab9d7347c72148bfe1be36a298194fdb2bfdf
daniel-reich/ubiquitous-fiesta
/veCWQHJNgeZQCNbdY_14.py
104
3.5
4
def root_digit(n): if len(str(n))<2: return n return root_digit(sum(map(int,str(n))))
a3e5231bc317f9138a9a850461a5dc720615f2d0
daniel-reich/ubiquitous-fiesta
/SChr3sBY5ZKwHBHLH_11.py
152
3.59375
4
def sort_it(lst): tp = [[x,x] if isinstance(x, int) else [x,x[0]] for x in lst] ls = sorted(tp, key= lambda x : x[1]) return [x[0] for x in ls]
5733121b376f10156af1c9e8e0704ab8703a9e65
daniel-reich/ubiquitous-fiesta
/5h5uAmaAWY3jSHA7k_2.py
210
3.71875
4
from itertools import groupby def landscape_type(lst): up = [a < b for a, b in zip(lst, lst[1:]) if a != b] if len(list(groupby(up))) == 2: return 'mountain' if up[0] else 'valley' return 'neither'
c636279531953764a39df1121db6f93a9211f2e4
daniel-reich/ubiquitous-fiesta
/WPojigJER35bJT6YH_12.py
77
3.515625
4
def reversed_binary_integer(num): return int('0b'+bin(num)[2:][::-1], 2)
fb1487be19354608ef51eaab200233a9d845654a
daniel-reich/ubiquitous-fiesta
/xYpG6ry6CLqgcwRWC_5.py
125
3.6875
4
def sum_two_smallest_nums(lst): lst.sort() for i in range(len(lst)): if (lst[i] >=0): return lst[i]+lst[i+1]
d0540c718154df149e042ed5a0091cb8e0113583
daniel-reich/ubiquitous-fiesta
/8gE6FCdnWbECiR7ze_7.py
1,133
3.5625
4
def smith_type(n): if n == 1: return "Not a Smith" if is_prime(n): return "Trivial Smith" y, up_x, down_x, x, up_y, down_y = sum(prime_factorisation(n)), n+1, n-1, n, sum(prime_factorisation(n+1)), sum(prime_factorisation(n-1)) while x > 9: x = sum([int(y) for y in str(x)]) while y > 9: y = sum([int(z) for z in str(y)]) if x != y: return ("Not a Smith") if not is_prime(up_x): while up_x > 9: up_x = sum([int(y) for y in str(up_x)]) while up_y > 9: up_y = sum([int(z) for z in str(up_y)]) if up_x == up_y: return "Youngest Smith" if not is_prime(down_x): while down_x > 9: down_x = sum([int(y) for y in str(down_x)]) while down_y > 9: down_y = sum([int(z) for z in str(down_y)]) if down_x == down_y: return "Oldest Smith" return "Single Smith" def is_prime(n): for x in range(2,n//2+1): if n % x == 0: return False return True def prime_factorisation(num): x = 2 result = [] while not is_prime(num): while num % x == 0: result.append(x) num = num // x x+=1 result.append(num) if 1 in result: del result[result.index(1)] return result
66c099329dd6e760841775b457697ba032aa9423
daniel-reich/ubiquitous-fiesta
/JgYPQrYdivmqN4KKX_1.py
366
3.703125
4
def BMI(weight, height): w = float(weight.split(' ')[0]) * (0.453592 if 'pound' in weight else 1) h = float(height.split(' ')[0]) * (0.0254 if 'inch' in height else 1) bmi = round(w / h**2, 1) res = 'Underweight' if bmi < 18.5 \ else 'Normal weight' if bmi < 25 \ else 'Overweight' if bmi < 30 \ else 'Obesity' return '%s %s' % (bmi, res)
b9dc26a747ad96a48483a4cf2c8a2597f10c32f8
daniel-reich/ubiquitous-fiesta
/QEL3QAY9ZhSkZcEih_8.py
263
3.6875
4
import re ​ ## Use Bitwise Operator (% modulo operator disallowed.) def is_odd(n): return "Yes" if (n & 1) else "No" ​ ## Use Regular Expression (% modulo operator disallowed.) def is_even(n): return "Yes" if re.findall(r'\d*[02468]$', n) else "No"
7f126dc10a4a7f043a1f34dcf74e46e2458a4287
daniel-reich/ubiquitous-fiesta
/GP6CEr9a5CMqPHY7C_17.py
513
3.59375
4
def words_to_sentence(words): if words == None: return "" else: output = "" realwords = [k for k in words if k != None and k != ""] for i in range(len(realwords)): if realwords[i] != None and realwords[i] != "": if i < len(realwords) - 2: output = output + realwords[i] + ", " elif i == len(realwords) - 2: output = output + realwords[i] + " and " elif i == len(realwords) - 1: output = output + realwords[i] ​ return output
78e5534e25ba47782bfa14e7d27d0b2631665720
daniel-reich/ubiquitous-fiesta
/28wYr5mXCa5hMimHZ_23.py
163
3.609375
4
import re def valid_name(name): regex = r'^([A-Z]\.\s([A-Z]\.\s)?|[A-Z][a-z]+\s([A-Z]\.\s|[A-Z][a-z]+\s)?)([A-Z][a-z]+)$' return bool(re.match(regex, name))
6d044d1a64802bb43d4a4bb44d75aa7ec8f0a3eb
daniel-reich/ubiquitous-fiesta
/yyCGJKP442qtTD9Ek_0.py
168
3.78125
4
def sums_of_powers_of_two(n): res, binary = [], bin(n)[2:] for idx, i in enumerate(reversed(binary)): if i == '1': res.append(2 ** idx) return res
76b7516649ab0954fd256d82a6163b2b91baebcf
daniel-reich/ubiquitous-fiesta
/ke4FSMdG2XYxbGQny_12.py
91
3.71875
4
def even_odd_transform(lst, n): return [(x-2*n) if x%2 == 0 else (x+2*n) for x in lst]
1445a83e92749e5aef326af356fe1e81821865dd
daniel-reich/ubiquitous-fiesta
/HzeTvQqnH2afZs6GY_21.py
381
3.609375
4
def generate_rug(n, direction): def left(n): lst = [] for i in range(n): lst.append(list(range(i, 0, -1)) + list(range(0, n - i))) return lst ​ def right(n): lst = [] for i in range(n): lst.append(list(range(n - 1 - i, 0, -1)) + list(range(0, i + 1))) return lst if direction == "left": return left(n) else: return right(n)
c022f85a331d09386a5ec33a04f0cbbca285fde3
daniel-reich/ubiquitous-fiesta
/WY7r2XtarpupNDWE8_8.py
1,709
3.75
4
def tower_of_hanoi_even(disks, move): pegs = [list(range(1, disks + 1))[::-1], [], []] m = 0 while m < move: m += 1 if m % 3 == 1: # make legal move between A and B p1, p2 = 0, 1 elif m % 3 == 2: # make legal move between A and C p1, p2 = 0, 2 else: # make legal move between B and C p1, p2 = 1, 2 if len(pegs[p2]) == 0: pegs[p2].append(pegs[p1].pop()) elif len(pegs[p1]) == 0: pegs[p1].append(pegs[p2].pop()) else: if pegs[p1][-1] < pegs[p2][-1]: pegs[p2].append(pegs[p1].pop()) else: pegs[p1].append(pegs[p2].pop()) return tuple(pegs) ​ def tower_of_hanoi_odd(disks, move): pegs = [list(range(1, disks + 1))[::-1], [], []] m = 0 while m < move: m += 1 if m % 3 == 1: # make legal move between A and C p1, p2 = 0, 2 elif m % 3 == 2: # make legal move between A and B p1, p2 = 0, 1 else: # make legal move between B and C p1, p2 = 1, 2 if len(pegs[p2]) == 0: pegs[p2].append(pegs[p1].pop()) elif len(pegs[p1]) == 0: pegs[p1].append(pegs[p2].pop()) else: if pegs[p1][-1] < pegs[p2][-1]: pegs[p2].append(pegs[p1].pop()) else: pegs[p1].append(pegs[p2].pop()) return tuple(pegs) ​ def tower_of_hanoi(disks, move): if disks == 1: return ([],[],[1]) return tower_of_hanoi_even(disks, move) if disks % 2 == 0 else tower_of_hanoi_odd(disks, move)
f52b24f99779d7c509f9f31b86ad73519499b6de
daniel-reich/ubiquitous-fiesta
/6M4gYkxWTsE6Rxhge_6.py
231
3.578125
4
def prime_num(n): ​ if n > 1: for i in range(2, n): if n % i == 0: return False return True else: return False ​ ​ ​ def all_prime(lst): ans = [prime_num(i) for i in lst] return all(ans)
00f0923b21ccf05127b5f410fdc6ef0f3baffc0d
daniel-reich/ubiquitous-fiesta
/iHfq7KA8MBuZqBGgo_2.py
178
3.53125
4
def is_legitimate(lst): if lst[0].count(1) == 0 and lst[-1].count(1) == 0: for i in lst: if 1 == i[0] or i[-1]: return False return True return False
b0c04d2911c23c9deb8ec0674791def3953e6ede
daniel-reich/ubiquitous-fiesta
/b67PHXfgMwpD9rAeg_24.py
163
3.796875
4
def plus_sign(txt): s=['1','2','3','4','5','6','7','8','9','0','+'] for i in range(0,len(txt),2): if(txt[i] not in s): return False return True
e0b5bf30defa246d000872dab66dc78c64b86283
daniel-reich/ubiquitous-fiesta
/z9tnydD5Fix3g3mas_12.py
542
3.578125
4
def check_pattern(lst, pattern): if len(lst) != len(pattern): return False if len([i for i in lst if i == lst[0]]) == len(lst): if len([i for i in pattern if i == pattern[0]]) != len(pattern): return False visited = [] for i in range(len(pattern)): pi = pattern[i] if pi not in visited: visited.append(pi) else: if lst[visited.index(pi)] != lst[i]: return False else: visited.append(pi) return True
deae3c9989d87eb193ba962e772b7ba031bc1429
daniel-reich/ubiquitous-fiesta
/nmoohLwP962r6P355_6.py
341
3.59375
4
def straight_digital(number): print(number) if number < 100: return 'Not Straight' ints = [] for char in str(number): ints.append(int(char)) diff = ints[1] - ints[0] for i in range(len(ints)-1): if ints[i+1] - ints[i] != diff: return 'Not Straight' if diff == 0: return 'Trivial Straight' return diff
bcf76b69d16c5f6c47453f21b22cf9783c1f23ef
daniel-reich/ubiquitous-fiesta
/yKxKe74BBRDbRRPHx_8.py
1,595
3.828125
4
class Number: def __init__(self, value): self.number = Number.__val__(value) def __val__(value): return value.number if isinstance(value, Number) else value ​ def __add__(self, value): return Number(self.number + Number.__val__(value)) def __sub__(self, value): return Number(self.number - Number.__val__(value)) def __mul__(self, value): return Number(self.number * Number.__val__(value)) ​ def __radd__(self, value): return value + self.number def __rsub__(self, value): return value - self.number def __rmul__(self, value): return value * self.number def __truediv__(self, value): v = Number.__val__(value) if v == 0: return 'ZeroDivisionError' return Number(self.number / v) def __floordiv__(self, value): v = Number.__val__(value) if v == 0: return 'ZeroDivisionError' return int(self.number // v) ​ def __int__(self): return int(self.number) ​ def __str__(self): return str(self.number) ​ def __eq__(self, other): return self.number == other.number if isinstance(other, Number) else False ​ def __lt__(self, other): return self.number < other.number if isinstance(other, Number) else False ​ def __le__(self, other): return self.number <= other.number if isinstance(other, Number) else False ​ def __gt__(self, other): return self.number > other.number if isinstance(other, Number) else False ​ def __ge__(self, other): return self.number >= other.number if isinstance(other, Number) else False ​ obj2 = Number(5)
e7b4b47a682eecdd1f806c2992631a70032b3a56
daniel-reich/ubiquitous-fiesta
/5XXXppAdfcGaootD9_16.py
91
3.625
4
def sum_odd_and_even(lst): return [sum(n * (n % 2 == i) for n in lst) for i in (0, 1)]
39ffcde4ff456c07e3d97c3d7b75549a07b8c977
daniel-reich/ubiquitous-fiesta
/zZyeau2MYcEc8Fdtk_24.py
572
3.625
4
def round_number(num, n): def is_divisible_by(n): def divisible_by(num): return num % n == 0 return divisible_by divisor = is_divisible_by(n) closest = [] for number in range(num - n, num + n + 1): divisible = divisor(number) if divisible == True: closest.append(number) minim = min(closest) maxim = max(closest) if len(closest) != 2: return False, 'L19' mindif = num - minim maxdif = maxim - num if mindif > maxdif: return maxim elif mindif < maxdif: return minim else: return maxim
7bba4be5a830a8c52c10dbc55d8482c7fdc83b30
daniel-reich/ubiquitous-fiesta
/d6wR7bcs4M6QdzpFj_6.py
293
3.578125
4
def repeat(lst, n): lst *= n return lst ​ def add(lst, x): lst.append(x) return lst ​ def remove(lst, i, j): l = [lst[k] for k in range(len(lst)) if k < i or k > j] lst.clear() lst += l return lst ​ def concat(lst, lst2): lst += lst2 return lst
a589654d709444c5989beb85b2d6abd1906a08e6
daniel-reich/ubiquitous-fiesta
/Jm4eKTENReSiQFw9t_6.py
86
3.546875
4
def invert_list(lst): a = []; for elem in lst: a.append(-elem) return a
dafdf2604897897e65692463ca1499f6134cf5b4
daniel-reich/ubiquitous-fiesta
/cGaTqHsPfR5H6YBuj_19.py
224
3.609375
4
def makeSandwich(i,f): a=len(i) newLst=[] for j in range(0,a): if(i[j]==f): newLst.append("bread") newLst.append(i[j]) newLst.append("bread") else: newLst.append(i[j]) return newLst
0421f19ffbddd63c2f86544d89dac099175e7962
daniel-reich/ubiquitous-fiesta
/ic9aKYukaRH2MjDyk_15.py
105
3.703125
4
def sort_by_last(txt): txt = txt.split(" ") txt.sort(key=lambda x: x[-1]) return (" ".join(txt))
7dced2486087286d58f8d7dbf6bf74e804d7d4aa
daniel-reich/ubiquitous-fiesta
/JPfqYkt6KGhpwfYK7_21.py
292
3.625
4
def replace_the(txt): l = [] txt = txt.split() for i in range(len(txt)): if txt[i] == "the" and txt[i + 1][0] in "aeiou": l.append("an") elif txt[i] == "the" and txt[i + 1][0] not in "aeiou": l.append("a") else: l.append(txt[i]) ​ return " ".join(l)
bed6141d1c6b036c4994e4f9b3589a08aa23e9f6
daniel-reich/ubiquitous-fiesta
/2tkcbQgPJZPPpzg2i_18.py
199
3.515625
4
def sum_of_holes(N): numHoles = 0 holes = { 0 : 1, 4 : 1, 6 : 1, 8 : 2, 9 : 1 } for i in range(N): for j in str(i+1): numHoles += holes.get(int(j), 0) return numHoles
a5a6fb5415819460de755c12c0684129dc09a585
daniel-reich/ubiquitous-fiesta
/YSTk5RMQQeocbAteg_6.py
107
3.59375
4
def tetra(n): if n == 1: return n else: return tetra(n-1) + sum([x for x in range(1, n+1)])
5bf5499b0d91883280b111b7c42efbb3462a302e
daniel-reich/ubiquitous-fiesta
/xRM8yTQRL3W6Wtdfi_2.py
335
3.59375
4
def quartic_equation(a, b, c): dis = (b**2 - 4*a*c) if dis < 0: return 0 if dis == 0: return 0 if a*b <0 else 1 if a*b == 0 else 2 n1, n2 = dis**0.5 - b, -dis**0.5 - b if n1 < 0 and n2 < 0: return 0 if n1 > 0 and n2 > 0: return 4 if n1 == 0: return 1 if n2 < 0 else 3 if n2 == 0: return 1 if n1 < 0 else 3 return 2
bdf5aac5dfce65f5a0370ed5c424f3a9fdf4e0d9
daniel-reich/ubiquitous-fiesta
/dFz2PDjQkXZ9FhEaz_14.py
127
3.84375
4
def letter_check(lst): for letter in lst[1].lower(): if not letter in lst[0].lower(): return False return True
ffd176d00d7ec56463c7dd1226f2859e29ad48ee
daniel-reich/ubiquitous-fiesta
/HWxNGdeoPxzievGa3_16.py
176
3.875
4
def is_strange_pair(txt1, txt2): if txt1 == txt2: return True elif txt1 == '' and len(txt2)> 0: return False return txt1[0] == txt2[-1] and txt1[-1] == txt2[0]
0124cb3276a7d42391b6b9938bd61b664daec464
daniel-reich/ubiquitous-fiesta
/Fx7hyoNTZNMGzc3uj_22.py
193
3.59375
4
def number_len_sort(lst): nums = [str(len(str(lst[i])))+str(i)+str(lst[i]) for i in range(len(lst))] nums.sort() for i in range(len(nums)): nums[i] = int(nums[i][2:]) return nums
39bacb14203e5c8d63ee5589dbc530caca1ca349
daniel-reich/ubiquitous-fiesta
/9sN5tvXZjYCsKb4Mx_19.py
190
3.625
4
def cube_diagonal(volume): import math side = float(volume **(1/3)) diagonal_base = (2*side*side)**(1/2) diagonal = (diagonal_base**2 + side**2)**(1/2) return round(diagonal, 2)
f25e7a4560fcde9427f723cd182c6c699edae30b
daniel-reich/ubiquitous-fiesta
/wwN7EwvqXKCSxzyCE_7.py
460
3.78125
4
def reorder_digits(lst, direction): new_lst = [] if direction == 'asc': for i in lst: i = list(str(i)) i.sort() i = int("".join(i)) new_lst.append(i) return new_lst elif direction == 'desc': for i in lst: i = list(str(i)) i.sort() i = list(reversed(i)) i = int("".join(i)) new_lst.append(i) return new_lst
e12a34c72c113146fbd09ee18edcdcc2dde9bde2
daniel-reich/ubiquitous-fiesta
/WH8AfHodqyj4gSB8K_13.py
677
3.71875
4
vowels = "AEIOU" consonants = ''.join([chr(i) for i in range(65, 91) if chr(i) not in vowels]) ​ def is_authentic_skewer(s): if s[0] not in consonants or s[-1] not in consonants: return False idx = s.find('-') if idx < 0: return False cnt = 0 while idx < len(s) and s[idx] == '-': cnt += 1 idx += 1 delim = '-' * cnt L = s.split(delim) for i in range(len(L)): c = L[i] if len(c) != 1: return False if i % 2 == 0: if c not in consonants: return False else: if c not in vowels: return False return True
9b7026ece875d955f89ba802439694d437696f91
daniel-reich/ubiquitous-fiesta
/F77JQs68RSeTBiGtv_18.py
186
3.546875
4
def diamond_sum(n): if n == 1: return 1 m = n // 2 total = n - m lst = [((2 * i + 1) * n) + 1 for i in range(1,n-1)] return total + (n * n) - m + sum(lst)
e7564315dc3bacb72acdd3f6bf8bc6722970acfe
daniel-reich/ubiquitous-fiesta
/abdsaD6gwjgAgevsG_11.py
265
3.515625
4
def power_ranger(power, minimum, maximum): square = [] square_list = [] for number in range(0,maximum+1): square = number**power if square in range(minimum,maximum+1): square_list.append(square) print(square_list) return(len(square_list))
9ea1a797f493ec0a111208aff59b6c8561a8afbf
daniel-reich/ubiquitous-fiesta
/fRjfrCYXWJAaQqFXF_18.py
439
3.640625
4
from operator import mul from functools import reduce ​ is_prime = lambda n: n > 1 and all(n%i for i in range(2, int(n**0.5 + 1))) ​ def first_n_primes(n): ''' Returns each of the first n prime numbers one at a time ''' p = 2 for _ in range(n): yield p p += 1 while not is_prime(p): p += 1 ​ PRIMES = list(first_n_primes(10)) ​ primorial = lambda n: reduce(mul,PRIMES[:n])
0c9eab7c5e56be5572991cbd26362065b52d3a5f
daniel-reich/ubiquitous-fiesta
/pAFxfge35bT3zj4Bs_12.py
129
3.609375
4
def area_shape(base, height, shape): if shape == "triangle": return 0.5 * base * height else: return base * height
157989cddf1d613d4de0c6c98fb23d72be64d3e7
daniel-reich/ubiquitous-fiesta
/i5KL9xzKt6WSBsds9_0.py
569
3.53125
4
def can_move(piece, current, target): x = (ord(target[0]) - 64) - (ord(current[0]) - 64) y = int(target[1]) - int(current[1]) ​ if piece == 'Pawn': return (x, y) == (0, 1) if piece == 'Knight': return sorted((x, y)) in ([-2, -1], [-2, 1], [-1, 2], [1, 2]) if piece == 'Bishop': return abs(x) == abs(y) if piece == 'Rook': return x == 0 or y == 0 if piece == 'Queen': return abs(x) == abs(y) or (x == 0 or y == 0) if piece == 'King': return sorted((abs(x), abs(y))) in ([0, 1], [1, 1])
5136da9022e461386450d3ac07941e41c4997e24
daniel-reich/ubiquitous-fiesta
/e9bCjrGRzDtr6CfNm_21.py
144
3.71875
4
def solve(a, b): if a == b: return 'Any number' if b == 3*a - 4 else 'No solution' else: return round((b - 3*a + 4) / (a - b), 3)
98d435041bca26adf21bc10bc7650fd2430b7ce7
daniel-reich/ubiquitous-fiesta
/N7zMhraJLCEMsmeTW_6.py
247
3.578125
4
def min_swaps(string): L = len(string) pattern1 = '01' * (L // 2 + 1) pattern2 = '10' * (L // 2 + 1) return min(sum([string[i] != pattern1[i] for i in range(L)]), sum([string[i] != pattern2[i] for i in range(L)]))
6b07ddda0cc8013bf452bc2a4587a91d6766e845
daniel-reich/ubiquitous-fiesta
/LByfZDbfkYTyZs8cD_20.py
99
3.796875
4
import math def areaofhexagon(x): return round(((3*math.sqrt(3))*x**2)/2,1) if x > 0 else None