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 |
|---|---|---|---|---|---|---|
1fe19f071715af3eb9cd6032a4a6f2f73868cc37 | daniel-reich/ubiquitous-fiesta | /kjJWvK9XtdbEJ2EKe_21.py | 224 | 3.71875 | 4 |
def sort_array(lst):
swaps = True
while swaps:
swaps = False
for i in range(1,len(lst)):
if lst[i-1] > lst[i]:
lst[i-1], lst[i] = lst[i], lst[i-1]
swaps = True
return lst
|
933064e924613a738985593d6f0317f3c20f5c2e | daniel-reich/ubiquitous-fiesta | /YTf8DZbTkzJ3kizNa_21.py | 285 | 3.546875 | 4 |
def moran(n):
counter = 0
x = sum([int(i) for i in str(n)])
if n % x == 0:
p = int(n/x)
for i in range(1,p+1):
if p % i == 0:
counter += 1
if counter == 2:
return "M"
return "H"
return "Neither"
|
9104a02fdd4c048862e96860338b320e9c75dbf3 | daniel-reich/ubiquitous-fiesta | /WS6hR6b9EZzuDTD26_7.py | 319 | 3.71875 | 4 |
def no_duplicate_letters(phrase):
noDups = True
words = phrase.split(" ")
print(words)
for word in words:
if not noDups:
break
previouslyUsed = []
for letter in word:
if letter in previouslyUsed:
noDups = False
break
previouslyUsed.append(letter)
return noDups
|
1bacee037f9295c435de9a9cafa9b400e6b61fb3 | daniel-reich/ubiquitous-fiesta | /6CvfzetG9PNG9ANPu_5.py | 576 | 3.890625 | 4 |
cipher = {"a" : "k", "b" : "g", "c" : "m", "d" : "q", "e" : "u", "f" : "t",
"g" : "b", "h" : "x", "i" : "z", "j" : "o", "k" : "a", "l" : "n",
"m" : "c", "n" : "l", "o" : "j", "p" : "w", "q" : "d", "r" : "y",
"s": "v", "t": "f", "u": "e", "v": "s", "w": "p", "x": "h",
"y": "r", "z": "i"}
def mubashir_cipher(message):
message = message.lower()
new_message = ""
for letter in message:
if letter in cipher:
new_message += cipher[letter]
else:
new_message += letter
return new_message
|
2b3934a18cb395db8a4b2c1b8963e25f3014f0e7 | daniel-reich/ubiquitous-fiesta | /GWBvmSJdciGAksuwS_10.py | 120 | 3.734375 | 4 |
def find_letters(word):
lst=[]
for char in word:
if word.count(char)==1:
lst.append(char)
return lst
|
ff18a0cb36f3b409fdca4818f8b874003d0d38de | daniel-reich/ubiquitous-fiesta | /yfTyMb3SSumPQeuhm_10.py | 142 | 3.796875 | 4 |
def fibonacci(n):
a, b, c = 1, 1, 2
while n > 2:
a, b = a*a + b*b, a*b + b*c
c = a + b
n //= 2
return b
|
0bfffcf5196c835d5a0357d26f395a4201bc3e7f | daniel-reich/ubiquitous-fiesta | /W8rasxGkqr6JHEdiv_6.py | 337 | 3.53125 | 4 |
from itertools import permutations,product
def countdown(operands, target):
n = len(operands)
for p in permutations([str(k) for k in operands], n):
for q in product(*[['+','-','*','//']]*(n-1)):
exp = ''.join([[p,q][i%2][i//2] for i in range(2*n-1)])
if eval(exp) == target:
return exp
return str(target)
|
6c0127b66ea4457450f77a382c4bd9d39aa24d5d | daniel-reich/ubiquitous-fiesta | /ZJGBGyZRNrbNtXJok_9.py | 138 | 3.546875 | 4 |
from string import ascii_lowercase as al
def nearest_vowel(s):
return sorted((abs(al.index(s)-al.index(c)),c) for c in 'aeiou')[0][1]
|
1df1de2e5c8623d3799957afa3649421acc19299 | daniel-reich/ubiquitous-fiesta | /q5jCspdCvmSjKE9HZ_14.py | 332 | 3.53125 | 4 |
import functools
def gcf(num1,num2):
factors = list(filter(lambda x: num1 % x == 0 and num2 % x == 0,range(1,num1+1)))
return factors[-1]
def lcm(num1,num2):
gcd = gcf(min(num1,num2),max(num1,num2))
return (num1 // gcd) * num2
def lcm_of_list(numbers):
return functools.reduce(lambda x,y: lcm(x,y),numbers)
|
c030a8392019e550eb13a2382edb4495f456b31a | daniel-reich/ubiquitous-fiesta | /aQWPiDnfwdE7xnqDq_18.py | 308 | 3.625 | 4 |
def drange (*x):
if len(list(x)) == 1:
return tuple(range(x[0]))
elif len(list(x)) == 2:
return tuple(range(x[0],x[1]))
else:
z=[]
top=x[0]
while top < x[1]:
z.append(round(top,3))
top += x[2]
return tuple(z)
|
f7c24a3423eb2c60859dbf2e03eeef7675a26538 | daniel-reich/ubiquitous-fiesta | /ic9aKYukaRH2MjDyk_21.py | 95 | 3.59375 | 4 |
def sort_by_last(txt):
return " ".join(sorted(txt.split(" "), key= lambda word:word[-1:]))
|
704b50328b522d2de58c71f326d4982e736c3cd2 | daniel-reich/ubiquitous-fiesta | /abdsaD6gwjgAgevsG_2.py | 289 | 3.625 | 4 |
def power_ranger(power, minimum, maximum):
lst = [1,2,3,4,5,6,7,8,9,10]
a = 0
counter = 0
for num in lst:
a = num ** power
if (a >= minimum) and (a <= maximum):
counter += 1
elif a < minimum:
continue
elif a > maximum:
break
return counter
|
85d98e8e46ed061452ddbe37d909aed5aa58215a | daniel-reich/ubiquitous-fiesta | /kzZD8Xp3EC7bipfxe_23.py | 444 | 3.6875 | 4 |
def plus(n1, n2):
return n1 + n2
def minus(n1, n2):
return n1 - n2
def dict_key_from_value(dict, value):
return list(dict.keys())[list(dict.values()).index(value)]
def wordedMath(equ):
numbers = {
"zero": 0,
"one": 1,
"two": 2
}
operations = {
"plus": plus,
"minus": minus
}
n1, op, n2 = equ.lower().split()
return dict_key_from_value(numbers, operations[op](numbers[n1], numbers[n2])).title()
|
3896c5870f65a8260036f3b28d0cf22342d4455d | daniel-reich/ubiquitous-fiesta | /58RNhygGNrKjPXwna_20.py | 462 | 3.796875 | 4 |
def longest_nonrepeating_substring(txt):
longest = ""
index = 0
while len(txt) > 0:
index += 1
if len(txt[ : index]) != len(set(txt[ : index])):
if len(txt[ : index - 1]) > len(longest):
longest = txt[ : index - 1]
txt = txt[1 :]
index = 0
if index == len(txt):
if len(txt) > len(longest):
longest = txt
txt = []
return longest
|
d2a00ef8bdc65736a39205ed125054caef5a9441 | daniel-reich/ubiquitous-fiesta | /5x4uruF77BzWFFiQM_19.py | 139 | 3.546875 | 4 |
def pH_name(pH):
if pH<0 or pH>14 :return "invalid"
elif pH<7:return "acidic"
elif pH==7:return "neutral"
else:return "alkaline"
|
6f59e441341d2400bc1236387ae05658d4787376 | daniel-reich/ubiquitous-fiesta | /EJ2RqF9AEmk64mLsv_4.py | 119 | 3.53125 | 4 |
def lottery(ticket, win):
return ['Loser!', 'Winner!'][sum(any(ord(x)==s[-1] for x in s[0]) for s in ticket)>=win]
|
5a641c1d2d4c868da657f87d2c25a8480be31407 | daniel-reich/ubiquitous-fiesta | /EL3vnd5MWyPwE4ucu_8.py | 115 | 3.65625 | 4 |
def fibonacci(n):
a = 0
b = 1
i = 1
while i < n:
c = a + b
a, b = b, c
i +=1
return str(c)
|
9cebb3ce561f9fbff821d02630ecd26b4217c746 | daniel-reich/ubiquitous-fiesta | /SFAjxGWk9AbfwbXFN_19.py | 180 | 3.6875 | 4 |
def primes_below_num(n):
c = 2
l = []
while c < n+1:
if sum(1 for x in range(2, c + 1) if c % x == 0) == 1:
l.append(c)
c+=1
return l
|
43f668793ecece6716589f07824ad17eb5ce2f14 | daniel-reich/ubiquitous-fiesta | /QHuaoQuAJfWn2W9oX_18.py | 454 | 3.765625 | 4 |
def check_board(col, row):
col_dict = dict(zip(map(chr, range(ord('a'), ord('h')+1)), range(0,8)))
col_num = col_dict.get(col)
board = [[0 for _ in range(0,8)] for _ in range(8)]
for b_row in range(8):
for b_col in range(8):
if b_row == row-1 or b_col == col_num or abs(b_row - (row-1)) == abs(b_col - col_num):
board[b_row][b_col] = 1
board[row-1][col_num] = 0
return board[::-1]
|
b41159c0555bb163963ebe8feac04d6143f69553 | daniel-reich/ubiquitous-fiesta | /RvCEzuqacuBA94ZfP_9.py | 218 | 3.8125 | 4 |
def generate_hashtag(txt):
if len(txt.strip()) == 0:
return False
tag = "#"
for word in txt.split():
tag += word[0].upper() + word[1:].lower()
return tag if len(tag) <= 140 else False
|
ffb4876dfdddb1eb5adc5fc5ef97d0f4cbd59abe | daniel-reich/ubiquitous-fiesta | /dP9osvXn6r6F36wYF_13.py | 73 | 3.546875 | 4 |
def front3(text):
return text[:3] * 3 if len(text) > 3 else text * 3
|
d3bebd2238971d8ad0c5dd069934e2c982d0dd0e | daniel-reich/ubiquitous-fiesta | /G2QnBrxvpq9FacFuo_2.py | 241 | 3.515625 | 4 |
def possible_path(lst):
count = 0
if len(lst)>1:
for i in lst[1:]:
if isinstance(i,int) and isinstance(lst[count], int) or isinstance(i,str) and isinstance(lst[count],str):
return False
count += 1
return True
|
011a810bcf1fca931df1d81795466b2193dafc91 | daniel-reich/ubiquitous-fiesta | /JiLom4d6aBk7wAJcZ_24.py | 106 | 3.5 | 4 |
import math
def is_sastry(n):
num = math.sqrt(int(str(n) + str(n+1)))
return num == math.floor(num)
|
1514cc943a1c5d986c5eef8e4e398e59797ff174 | daniel-reich/ubiquitous-fiesta | /A7hyDnb72prWryeuY_20.py | 101 | 3.609375 | 4 |
def findLargestNum(nums):
max = 0
for a in nums:
if a > max:
max = a
return max
|
5380cd56e98a576bc30e2532b0c4f986ed1583b5 | daniel-reich/ubiquitous-fiesta | /fDfh3WJPPiiJwgTrW_5.py | 111 | 3.65625 | 4 |
def num_of_sublists(lst):
count = 0
for i in lst:
if type(i) == list:
count +=1
return count
|
492a2f7ed129b838b152aee50892f7758befa014 | daniel-reich/ubiquitous-fiesta | /FLgJEC8SK2AJYLC6y_22.py | 212 | 3.625 | 4 |
def possible_path(lst: list) -> bool:
moves = {1: (2,), 2: (1, 'H'), 'H': (2, 4), 3: (4,), 4: (3, 'H')}
for i in range(1, len(lst)):
if lst[i] not in moves[lst[i - 1]]:
return False
return True
|
8c3913daf1b2cd17868778c74b8e1be098946a4b | daniel-reich/ubiquitous-fiesta | /EJ2RqF9AEmk64mLsv_24.py | 322 | 3.625 | 4 |
def lottery(ticket, win):
miniwin=0
for i in range(0,len(ticket)):
for z in range(0,len(ticket[i][0])):
if(ord(ticket[i][0][z])==ticket[i][1]):
miniwin=miniwin+1
if(miniwin>=win):
return "Winner!"
else:
return "Loser!"
#print (ticket[i][0][z])
#print (ord(ticket[i][0][z]))
|
dce3132a60ee0e7e47e872085d4a9338b843fa7c | daniel-reich/ubiquitous-fiesta | /e6fL5EiwGZcsW7C5D_17.py | 332 | 3.578125 | 4 |
def alph_num(txt):
output=""
alphorder = {
"A": 0,"B": 1,"C": 2,"D": 3,"E": 4,"F": 5,"G": 6,"H": 7,"I": 8,"J": 9,"K": 10,"l": 11,"M": 12,"N": 13,"O": 14,"P": 15,
"Q": 16,"R": 17,"S": 18,"T": 19,"U": 20,"V": 21,"W": 22,"X": 23,"Y": 24,"Z": 25}
for i in txt:
output=output+str(alphorder[i])+' '
return output[:-1]
|
99f3e7e8c22c5a6d91d18d2c5b2353405c951d60 | daniel-reich/ubiquitous-fiesta | /Fej5HSzcvHMdm2i4N_10.py | 237 | 3.515625 | 4 |
def weight_allowed(car, p, max_weight):
matyikaaa = 0
for i in p:
matyikaaa = matyikaaa + i
max_weight = max_weight / 0.453592
if matyikaaa + car < max_weight:
return True
else:
return False
|
3b1208f9e0647dddc6ae8a5dd985506ad9c636f7 | daniel-reich/ubiquitous-fiesta | /xRM8yTQRL3W6Wtdfi_1.py | 357 | 3.765625 | 4 |
import math
def quartic_equation(a, b, c):
if c == 0:
# 0 is a solution:
return 1 if a * b >= 0 else 3
D = b**2 - 4 * a * c
if D < 0:
return 0
if D == 0:
return 2
z1 = (-b + math.sqrt(D)) / (2 * a)
z2 = (-b - math.sqrt(D)) / (2 * a)
if z1 < 0:
return 0
return 2 if z2 < 0 else 4
|
8bc793efaf435d630a6e23d42c50f218a35280d4 | daniel-reich/ubiquitous-fiesta | /xCFHFha5sBmzsNARH_0.py | 71 | 3.953125 | 4 |
def reverse(str):
return reverse(str[1:]) + str[0] if str else str
|
8d928b46ef4c9421a3d23cffdb4cf399640f9545 | daniel-reich/ubiquitous-fiesta | /B2jcSh2RG4GpQYuBz_17.py | 227 | 3.984375 | 4 |
import re
def is_valid_phone_number(txt):
print(txt)
txt_match=re.match("\(\d{3}\) \d{3}-\d{4}",txt,re.I)
if txt_match:
print(str(txt_match.group()))
return(txt_match.group()==txt)
else:
return(False)
|
2975c0bf692db6b6ce7f4974ba9900e4528725aa | daniel-reich/ubiquitous-fiesta | /q3zrcjja7uWHejxf6_14.py | 167 | 3.71875 | 4 |
def negative_sum(chars):
chars = ''.join([i if i.isdigit() else ' -' if i=='-' else ' ' for i in chars]).split()
return sum([int(i) for i in chars if int(i)<0])
|
3a9162859f9c71ee71b3b22c0ba05420853e4705 | daniel-reich/ubiquitous-fiesta | /MNePwAcuoKG9Cza8G_5.py | 143 | 3.609375 | 4 |
def build_staircase(height, block):
a = []
for i in range(height):
a.append([block] * (i + 1) + ['_'] * (height - i - 1))
return a
|
f71d83e4457f65f139a31e0605e146ed7589e80d | daniel-reich/ubiquitous-fiesta | /JgD9KHBYrDnKrGJ7a_14.py | 165 | 3.90625 | 4 |
def swap_dict(dic):
output = {}
for i in dic:
if dic[i] not in output:
output[dic[i]] = [i]
else:
output[dic[i]].append(i)
return output
|
4103a689dfff7c191bc2aa4c40a4cd4aa908a798 | daniel-reich/ubiquitous-fiesta | /smLmHK89zNoeaDSZp_12.py | 565 | 3.796875 | 4 |
class Country:
def __init__(self, name, population, area):
self.name = name
self.population = population
self.area = area
# implement self.is_big
self.is_big = self.population > 250000000 or self.area > 3000000
def compare_pd(self, other):
selfDens = self.population / self.area
otherDens = other.population / other.area
if selfDens > otherDens:
return self.name + " has a larger population density than " + other.name
else:
return self.name + " has a smaller population density than " + other.name
|
866c2c5b79912237fe0841bfca584d932c178ad4 | daniel-reich/ubiquitous-fiesta | /BcjsjPPmPEMQwB86Y_19.py | 581 | 3.640625 | 4 |
def func(txt,vowel:bool): # txt for text; set vowel=True for get_vowel / False otherwise
out=[]
print(txt)
for x in range(0,len(txt)):
if (txt[x] in ['a','e','i','o','u']) == vowel:
# print(x,":",txt[x])
for y in range(x,len(txt)):
# print(x,y,txt[x:y+1])
if (txt[y] in ['a','e','i','o','u']) == vowel:
out.append(txt[x:y+1])
out=list(set(out)) # transform to set to be unique
out.sort()
return(out)
def get_vowel_substrings(txt):
return(func(txt,True))
def get_consonant_substrings(txt):
return(func(txt,False))
|
ef4c9958ae4ee52d6d0e7a17c999b7b93c1a945a | daniel-reich/ubiquitous-fiesta | /7Y2C8g3fXXyK2R9Bn_5.py | 396 | 3.71875 | 4 |
def keyword_cipher(key, message):
keystr = ""
for k in key:
if k not in keystr:
keystr += k
for k in range(97, 123):
c = chr(k)
if c not in keystr:
keystr += c
enc = ""
for m in message:
if 'a' <= m <= 'z':
idx = ord(m) - 97
enc += keystr[idx]
else:
enc += m
return enc
|
e3bbfcea08f0a41efef7710f0e8af63cc3ea221e | daniel-reich/ubiquitous-fiesta | /CB3pKsWR3b7tvvxmN_14.py | 138 | 3.75 | 4 |
def is_palindrome(txt):
return ''.join(i for i in txt.lower() if i.isalpha()) == ''.join(i for i in txt.lower() if i.isalpha())[::-1]
|
bb103bdc06165c29ab31702fc97db0fcc1ff1e32 | daniel-reich/ubiquitous-fiesta | /Z8REdTE5P57f4q7dK_23.py | 201 | 3.578125 | 4 |
def collatz(n):
tally = []
while n > 1:
if n %2 == 0:
n = n//2
tally.append(n)
elif n %2 != 0:
n = (n * 3) + 1
tally.append(n)
return (len(tally)+1, max(tally))
|
225f9aba47e5ba73c55064621e8d865b607a434d | daniel-reich/ubiquitous-fiesta | /FWh2fGH7aRWALMf3o_18.py | 304 | 3.578125 | 4 |
def cleave(string, lst):
if not string:
return ''
for word in lst:
if string.startswith(word):
r = cleave(string[len(word):],lst)
if r == "Cleaving stalled: Word not found":
continue
return word + ' ' + r if r else word
return "Cleaving stalled: Word not found"
|
3138c72ba5b1a05f7e8cea6a92e42e1d062f670c | daniel-reich/ubiquitous-fiesta | /KZFEAv8Sqh9zW5eLS_23.py | 213 | 3.671875 | 4 |
def is_val_in_tree(tree, val):
for x in tree:
if isinstance(x, list):
if is_val_in_tree(x, val):
return True
if x == val:
return True
return False
|
5cfd10251ae92061487989805e1b9bc07b761c73 | daniel-reich/ubiquitous-fiesta | /K3qMssK6mF34ctXE5_13.py | 165 | 3.515625 | 4 |
def square_patch(n):
a = []
if n == 0:
return []
else:
for i in range(n):
a.append(n)
o = []
for k in range(n):
o.append(a)
return o
|
b9b8285a9ab479671dc2037bdda14f4214f71c64 | daniel-reich/ubiquitous-fiesta | /jijxZNn98jE9C2EWo_7.py | 101 | 3.546875 | 4 |
def automorphic(n):
if str(n) in str(n**2):
return True
else:
return False
|
263ed909fb83f2d81ae1fbc0fe9fe9826e15b322 | daniel-reich/ubiquitous-fiesta | /kAQT4vMX2iEAcs8uJ_14.py | 357 | 3.5 | 4 |
def longest_7segment_word(lst):
qualifies = []
for word in lst:
nogood = False
for letter in word:
if letter in ['k', 'v', 'm', 'w', 'x']:
nogood = True
if nogood:
continue
qualifies.append(word)
if qualifies:
temp = list(map(len, qualifies))
return qualifies[temp.index(max(temp))]
else:
return ""
|
361e24377b14806702468c0f526359becd26a59d | daniel-reich/ubiquitous-fiesta | /RvCEzuqacuBA94ZfP_24.py | 184 | 3.609375 | 4 |
def generate_hashtag(txt):
result = "#" + "".join(txt.title().strip().split())
if len(result) > 140 or len(result) == 1:
return False
else:
return result
|
10bc8a73bb7f7b3244853ad396a16e7dbf0424f3 | daniel-reich/ubiquitous-fiesta | /rPnq2ugsM7zsWr3Pf_13.py | 280 | 3.9375 | 4 |
def find_all_digits(nums):
digits = list(map(str, range(10)))
for num in nums:
for digit in str(num):
if digit in digits:
digits.remove(digit)
if not digits:
return num
return 'Missing digits!'
|
545c169dec1f69a5ceb190dd9a85b8953cbfbd1b | daniel-reich/ubiquitous-fiesta | /6cj6i2DACHTbtNnCD_6.py | 281 | 3.59375 | 4 |
from itertools import combinations
def two_product(lst, n):
if len(lst) != 0:
lst = sorted(lst)
x = list(combinations(lst, 2))
print(x)
for i in range(len(x)):
num1 = x[i][0]
num2 = x[i][1]
if num1 * num2 == n:
return [num1, num2]
|
5db14bc933c1a490286c4d853d94991405848b07 | daniel-reich/ubiquitous-fiesta | /YzZdaqcMsCmndxFcC_9.py | 538 | 3.578125 | 4 |
import collections
Point = collections.namedtuple("Point", "x y")
def centroid(x1, y1, x2, y2, x3, y3):
p1 = Point(x1, y1)
p2 = Point(x2, y2)
p3 = Point(x3, y3)
ordered = sorted([p1, p2, p3], key=lambda p: p.x + p.y)
slope = (ordered[2].y - ordered[0].y)/(ordered[2].x - ordered[0].x)
b = ordered[0].y - ordered[0].x * slope
if ordered[1].y == ordered[1].x * slope + b:
return False
else:
cx = (x1 + x2 + x3)/3
cy = (y1 + y2 +y3)/3
return (round(cx, 2), round(cy, 2))
|
29943f7d51f24e21b832f639bd4a0cee18412237 | daniel-reich/ubiquitous-fiesta | /vaufKtjX3gKoq9PeS_16.py | 346 | 3.640625 | 4 |
def ohms_law(v, r, i):
if (v is None and r is None) or (v is None and i is None) or (r is None and i is None):
return 'Invalid'
elif v is not None and r is not None and i is not None:
return 'Invalid'
elif v is None:
return round(r * i, 2)
elif r is None:
return round(v/i, 2)
elif i is None:
return round(v/r, 2)
|
0ee770873d74465e00cb2e0c739b0b43043afc35 | daniel-reich/ubiquitous-fiesta | /arobBz954ZDxkDC9M_13.py | 174 | 3.734375 | 4 |
def next_prime(num):
cond = 2**(num-1) % num == 1
if cond:
return num
else:
while(not cond):
num += 1
cond = 2**(num-1) % num == 1
return num
|
1d5dac453505b1bec99cbcd011204981285a40cf | daniel-reich/ubiquitous-fiesta | /KEz3TAQfh9WxSZMLH_10.py | 129 | 3.59375 | 4 |
def count_all(txt):
return {'LETTERS': len([i for i in txt if i.isalpha()]), 'DIGITS': len([i for i in txt if i.isdigit()])}
|
f487e3b1067f18c6e591b7d35d4651c2ea4eaad1 | daniel-reich/ubiquitous-fiesta | /vf4Htv8Cc7GPQAuTP_16.py | 184 | 3.609375 | 4 |
def list_operation(x, y, n):
range_list = range(x, y + 1)
main_list = []
for i in range_list:
if i % n == 0:
main_list.append(i)
return main_list
|
b990090854817511193a1c0a1f6914cbec1b12d7 | daniel-reich/ubiquitous-fiesta | /ouWxFayrk3ySG6jsg_11.py | 746 | 3.796875 | 4 |
def check_triple(triple):
# check whether a triple of values is a winning position:
return len(set(triple)) == 1 and triple[0] != 's'
def isSolved(board):
# first check if there's a winner:
# check rows:
for row in board:
if check_triple(row):
return row[0]
# check columns:
for col in range(3):
column = [board[row][col] for row in range(3)]
if check_triple(column):
return column[0]
# check diagonals:
if check_triple([board[i][i] for i in range(3)]):
return board[0][0]
if check_triple([board[i][2-i] for i in range(3)]):
return board[2][0]
#
# no winner:
return "Draw"
def who_won(board):
return isSolved(board)
|
46a0b1623c38c0ba54eb819fecb9572ee820e4de | daniel-reich/ubiquitous-fiesta | /wwN7EwvqXKCSxzyCE_19.py | 148 | 3.53125 | 4 |
def reorder_digits(lst, dir):
for i in range(len(lst)):
lst[i]=int(''.join(sorted(str(lst[i]),reverse=(dir=='desc'))))
return lst
|
b8e49a447e0555dde9a63e0e779b32cbd7ee5663 | daniel-reich/ubiquitous-fiesta | /CzrTZKEdfHTvhRphg_1.py | 197 | 3.578125 | 4 |
from fractions import*
def mixed_number(f):
n,d=map(abs,map(int,f.split('/')))
n,d=n//gcd(n,d),d//gcd(n,d)
return'-'*(f[0]=='-')+(('%s %s/%s'%(n//d,n%d,d),'%s/%s'%(n,d))[n<d],str(n))[d==1]
|
6b902fbae1a1961a4ef94090ce7935c23ab0ec67 | daniel-reich/ubiquitous-fiesta | /KcD3bABvuryCfZAYv_16.py | 238 | 3.546875 | 4 |
def most_frequent_char(lst):
k=''.join(lst)
import collections
c=collections.Counter(k)
maximum = max(c.values())
keys = [key for key, value in c.items() if value == maximum]
keys.sort()
return(keys)
|
dd6fb2eee379316b9ab2f2ad690e8dfbdce6892d | daniel-reich/ubiquitous-fiesta | /HBuWYyh5YCmDKF4uH_1.py | 368 | 3.703125 | 4 |
def almost_sorted(lst):
def sf(lst):
if len(set(lst)) != len(lst):
return False
v = [lst[i + 1] - lst[i] > 0 for i in range(len(lst) - 1)]
return len(set(v)) == 1
k = sorted(lst)
if (lst == k) or (lst == k[::-1]):
return False
for i in range(len(lst)):
lst1 = lst[:i] + lst[i + 1:]
if sf(lst1):
return True
return False
|
f185f14a7e970f9bc5e434fb8505f7f93fdb05ff | daniel-reich/ubiquitous-fiesta | /hxr3ZyPw2bZzrHEsf_10.py | 188 | 3.75 | 4 |
def make_title(txt):
new_txt = txt[0].upper()
for n in range(1, len(txt)):
if txt[n-1] == ' ':
new_txt += txt[n].upper()
else:
new_txt += txt[n]
return new_txt
|
6afc1b5a348c3b64981583d34f6a2823321503c5 | daniel-reich/ubiquitous-fiesta | /aQWPiDnfwdE7xnqDq_9.py | 381 | 3.703125 | 4 |
def drange(*args):
myans = []
if len(args) == 3:
a = args[0]
while a < args[1]:
myans.append(round(a,3))
a += args[2]
return tuple(myans)
elif len(args) == 2:
a = args[0]
while a < args[1]:
myans.append(round(a,3))
a += 1
return tuple(myans)
else:
for i in range(args[0]):
myans.append(i)
return tuple(myans)
|
49d0b9862924599d9bb972cf571292846add2b50 | daniel-reich/ubiquitous-fiesta | /FbQqXepHC4wxrWgYg_8.py | 425 | 3.90625 | 4 |
def prime_divisors(num):
def divisors(num):
factors = []
for n in range(1, num//2 + 1):
if num % n == 0:
factors.append(n)
factors.append(num//n)
return factors
def is_prime(num):
if num <= 1:
return False
for n in range(2, num):
if num % n == 0:
return False
return True
return sorted([n for n in list(set(divisors(num))) if is_prime(n) == True])
|
fd4cb56b584202400af37e82ff31ea0933028672 | daniel-reich/ubiquitous-fiesta | /YN33GEpLQqa5imcFx_15.py | 177 | 3.78125 | 4 |
from math import factorial as f
def pascals_triangle(row):
x = []
for col in range(row + 1):
x.append(str(f(row)//(f(col)*f(row-col))))
return ' '.join(x)
|
bafd38a5f43541edfb7b498fb6b4b4d627494716 | daniel-reich/ubiquitous-fiesta | /Ff84aGq6e7gjKYh8H_4.py | 139 | 3.703125 | 4 |
def minutes_to_seconds(time):
return int(time.split(':')[0])*60 + int(time.split(':')[1]) if int(time.split(':')[1]) < 60 else False
|
fc3592f5de22ed8393851e9b819261589fc2a192 | daniel-reich/ubiquitous-fiesta | /yKMxg88HGXmLhirht_8.py | 213 | 3.765625 | 4 |
import string
def add_letters(a):
total = sum((string.ascii_lowercase.index(letter)+1 for letter in a))
return string.ascii_lowercase[total-1] if total < 26 else string.ascii_lowercase[(total-1)%26]
|
1f0ba387638607c54191009389095e3340e5df82 | daniel-reich/ubiquitous-fiesta | /smLmHK89zNoeaDSZp_24.py | 542 | 3.828125 | 4 |
class Country:
def __init__(self, name, population, area):
self.name = name
self.population = population
self.area = area
self.is_big = self.area >= 3 * pow(10, 6)
self.density = round(self.population / self.area)
def compare_pd(self, other):
condition = 'larger' if self.density > other.density else 'smaller'
return '{country} has a {condition} population density than {other_country}'.format(country = self.name, condition = condition, other_country = other.name)
|
969013059f7fec77e3deb4236e1a59ffa74c7911 | daniel-reich/ubiquitous-fiesta | /hAsdEPWwufWoJos32_4.py | 139 | 3.546875 | 4 |
def no_yelling(phrase):
for foo in range(len(phrase) - 1,-1,-1):
if phrase[foo] not in "?!":
break
return phrase[:foo + 2]
|
fd444fd70684eaa6c7b699fdd1b4550a87656fb8 | daniel-reich/ubiquitous-fiesta | /e5XZ82bAk2rBo9EfS_14.py | 996 | 3.5 | 4 |
def bed_time(*times):
time = []
for i in range(len(times)):
first_hour = get_HourMinutes(times,i , 0)[0]
first_minutes = get_HourMinutes(times,i , 0)[1]
second_hour = get_HourMinutes(times,i , 1)[0]
second_minutes = get_HourMinutes(times,i , 1)[1]
sleep_hour = (first_hour-second_hour)%24
sleep_minutes = (first_minutes-second_minutes)%60
if (first_minutes-second_minutes) < 0:
sleep_hour += -1
time_string = ""
if sleep_hour >= 10:
time_string = str(sleep_hour) + ":"
else:
time_string = "0" + str(sleep_hour) + ":"
if sleep_minutes >= 10:
time_string += str(sleep_minutes)
else:
time_string += "0" + str(sleep_minutes)
time.append(time_string)
return time
def get_HourMinutes(times, i, index_time):
hourMinutes = []
time = times[i]
index = time[index_time].find(":")
hourMinutes.append(int(time[index_time][:index]))
hourMinutes.append(int(time[index_time][index+1:]))
return hourMinutes
|
426bd8877ce42e7e98e8533f58016802f2500b8e | daniel-reich/ubiquitous-fiesta | /zE37mNeG4cn6HesaP_20.py | 287 | 3.546875 | 4 |
def max_ham(s1, s2):
if (len(s1) != len(s2)) or (len(set(s1+s2)) != len(set(s1))) or ((abs(len(set(s1)) - len(set(s2))) >= 1)):
return False
else:
temp = sum(1 for i in range(len(s1)) if s1[i] != s2[i])
if temp == len(s1):
return True
else:
return temp
|
091a8dfc75be8b3d7a5f77e067747adf24fc887b | daniel-reich/ubiquitous-fiesta | /hAsdEPWwufWoJos32_24.py | 180 | 3.78125 | 4 |
def no_yelling(phrase):
if (phrase[-2:] == "!!"):
return phrase.strip("!") + "!"
elif (phrase[-2:] == "??"):
return phrase.strip("?") + "?"
else:
return phrase
|
05c9200a084d9e976159abc23aa37a7bca0727c9 | daniel-reich/ubiquitous-fiesta | /gbybFzt2tLa5zfpHc_0.py | 195 | 3.625 | 4 |
from itertools import combinations
def three_sum(lst):
found = []
for i in combinations(lst, 3):
if sum(i) == 0 and list(i) not in found:
found.append(list(i))
return found
|
36471d0cd41e61d3d46304c2d62f88090125da6d | daniel-reich/ubiquitous-fiesta | /ESAWnF3ySrFusHhYF_16.py | 165 | 3.65625 | 4 |
def edit_words(lst):
return [change(w) for w in lst]
def change(word):
word = word.upper()[::-1]
n = (len(word)+1)//2
return word[:n] + '-' + word[n:]
|
874c45994daabb94c00ab9aa44e25b9d231fec2f | daniel-reich/ubiquitous-fiesta | /FSRLWWcvPRRdnuDpv_7.py | 559 | 3.640625 | 4 |
def time_to_eat(current_time):
split = current_time.index(":")
hour = int(current_time[:split])
if current_time[-4::] == "p.m.":
hour += 12
mins = int(current_time[split+1:split+3])
if hour < 7:
hoursuntil = 6 - hour
minsuntil = 60 - mins
elif hour < 12:
hoursuntil = 11 - hour
minsuntil = 60 - mins
elif hour < 19:
hoursuntil = 18 - hour
minsuntil = 60 - mins
else:
hoursuntil = 30 - hour
minsuntil = 60 - mins
if minsuntil == 60:
minsuntil = 0
hoursuntil += 1
return [hoursuntil, minsuntil]
|
985afc024f36e6a1fae9ebd62277d6ecb4783fa2 | daniel-reich/ubiquitous-fiesta | /WS6hR6b9EZzuDTD26_12.py | 198 | 3.59375 | 4 |
def no_duplicate_letters(phrase):
for wrds in phrase.split():
letter = ''
for i in sorted(wrds):
if(letter == i):
return False
else:
letter = i
return True
|
90c78a3252fca7c5d25d4d10713456c3f5cbb0e4 | daniel-reich/ubiquitous-fiesta | /B5J4Bfgg7PoDHBBZQ_17.py | 237 | 3.859375 | 4 |
def area(p1,p2,p3):
return abs((p1[0]*(p2[1]-p3[1]) + p2[0]*(p3[1]-p1[1]) + p3[0]*(p1[1]-p2[1]))/2)
def within_triangle(p1, p2, p3, test):
return area(p1,p2,test) + area(p1,p3,test) + area(p2,p3,test) == area(p1,p2,p3)
|
0e2520e1812854cc634305b70c01d067679efb83 | daniel-reich/ubiquitous-fiesta | /xmyNqzxAgpE47zXEt_12.py | 257 | 3.828125 | 4 |
def is_alphabetically_sorted(sentence):
for e in sentence.split(" "):
e = e.replace(".", "")
if len(e) > 2:
if e ==''.join(sorted(e)):
return True
else:
continue
return False
|
034e681cfd6dc7e9d1bbe64e82ff454bf65d9a3c | daniel-reich/ubiquitous-fiesta | /kozqCJFi4de2JnR26_15.py | 493 | 3.796875 | 4 |
# Hello World program in Python
def fib_str(n, txt):
my_word = ""
my_list = []
my_list.append(txt[0])
my_list.append(txt[1])
my_word+=txt[0]+","+" "+txt[1]
if (n == 2):
my_word = txt[0]+","+" "+txt[1]
return my_word
elif (n>2):
for i in range (2,n):
my_list.append(my_list[i-1]+my_list[i-2])
for i in range (2,len(my_list)):
my_word+=","+" "+my_list[i]
return my_word
txt = ["n","k"]
print(fib_str(6,txt))
|
041e6180cf3452d934b22127992d777f7733947f | daniel-reich/ubiquitous-fiesta | /GWBvmSJdciGAksuwS_19.py | 87 | 3.53125 | 4 |
def find_letters(word):
lst = [l for l in word if word.count(l) <= 1]
return lst
|
fcd7b265e26106417e65f0e1e6962ca592f9d0ab | daniel-reich/ubiquitous-fiesta | /q7BdzRw4j7zFfFb4R_20.py | 519 | 3.6875 | 4 |
def merge_arrays(a, b):
newlist = []
length = min((len(a)),(len(b)))
print(length)
if ((len(a))==(len(b))):
#go through a
for x in range(len(a)):
newlist.append(a[x])
newlist.append(b[x])
elif ((len(a))<(len(b))):
#go through a
for x in range(len(a)):
newlist.append(a[x])
newlist.append(b[x])
newlist += (b[x+1:])
else:
#go through b
for x in range(len(b)):
newlist.append(a[x])
newlist.append(b[x])
newlist += (a[x+1:])
return newlist
|
1da0be0c2afb45ab8d3e45e9a62249e41611227a | daniel-reich/ubiquitous-fiesta | /8Ko5tPg8Ch5SRCAhA_3.py | 91 | 3.71875 | 4 |
def fibonacci(num):
a, b = 1, 1
for i in range(1, num):
a, b = b, a+b
return b
|
52c966d8563c6bfce061c24edae4ffd2283c0a13 | daniel-reich/ubiquitous-fiesta | /pGRAtBbwSMjpXNGnP_1.py | 202 | 3.75 | 4 |
def is_sorted(words, alphabet):
translation = {alphabet[i]: chr(97+i) for i in range(26)}
words = [''.join([translation[c] for c in word]) for word in words]
return words == sorted(words)
|
d451cf5731583ff62ffd59d212fd9f62aa893452 | daniel-reich/ubiquitous-fiesta | /4afgmFpLP6CpwtRMY_23.py | 681 | 3.5 | 4 |
def validate_list9(lst):
return len(lst) == 9 and all(lst.count(i) == 1 for i in range(1, 10))
def sudoku_validator(x):
for row in x:
if not validate_list9(row):
return False
for j in range(9):
col = []
for i in range(9):
col.append(x[i][j])
if not validate_list9(col):
return False
for i in range(3):
for j in range(3):
box_3x3 = (x[i * 3][j * 3: (j + 1) * 3]
+ x[i * 3 + 1][j * 3: (j + 1) * 3]
+ x[i * 3 + 2][j * 3: (j + 1) * 3])
if not validate_list9(box_3x3):
return False
return True
|
a0572c8f3ba9aa177c72de3e7a664cf6f1d1ce53 | daniel-reich/ubiquitous-fiesta | /ZaEFRDBZ7ZMTiSEce_18.py | 236 | 3.9375 | 4 |
def find_nemo(sentence):
mystring = sentence.replace(",","")
x = mystring.split(" ")
print(x)
if "Nemo" in x:
val = x.index("Nemo") +1
return "I found Nemo at " +str(val) +"!"
else:
return "I can't find Nemo :("
|
6c4348c200af5ed96a9f134f95e6f5da496e067a | daniel-reich/ubiquitous-fiesta | /mhcjnns2WWiHWexP7_16.py | 904 | 3.546875 | 4 |
def calculate_arrowhead(lst):
if isinstance(lst, list):
#print("Het is een list")
pass
else:
print("het is geen list, maar een {}".format(type(lst)))
aantal_zetten = len(lst)
#print("aantal zetten is {}".format(aantal_zetten))
verplaatsing = 0
for zet in lst:
#print(zet)
if '<' in zet:
#print("Links")
verplaatsing -= len(zet)
elif '>' in zet:
#print("Rechts")
verplaatsing += len(zet)
else:
print("Foute input!")
#print("De verplaatsing is {}".format(verplaatsing))
if verplaatsing < 0:
visueel = abs(verplaatsing) * '<'
#print("Links")
elif verplaatsing > 0:
#print("Rechts")
visueel = verplaatsing * '>'
elif verplaatsing == 0:
#print("Blijf staan...")
visueel = ''
return visueel
|
4cc4f1d4e56ee8271c4fbc45bc629c8b75dc1b9c | daniel-reich/ubiquitous-fiesta | /6rztMMwkt6ijzqcF6_16.py | 155 | 3.625 | 4 |
def is_repeated(strn):
for i in range(1, len(strn) // 2 + 1):
if strn.count(strn[0:i]) == len(strn) / i:
return len(strn) / i
return False
|
ad80f8f3ce3989fd965dd567e0f7d16352ef9c9e | daniel-reich/ubiquitous-fiesta | /quMt6typruySiNSAJ_18.py | 310 | 3.546875 | 4 |
def shuffle_count(num):
#gather data
lst = list(range(1,num+1))
lst2 = lst.copy()
temp = []
count = 0
while temp != lst:
temp = []
for i in range(0,(num//2)):
temp = temp + [lst2[i],lst2[i+(num//2)]]
count += 1
lst2 = temp
return count
|
292bf45d76e787b2dbaec663ca4742bcbc76c7f5 | daniel-reich/ubiquitous-fiesta | /kEww9Hjds5Zkgjyfj_15.py | 194 | 3.71875 | 4 |
def replace_next_largest(lst):
l = lst[:]
l.sort()
res = []
for el in lst:
i = l.index(el)
if el == l[-1]:
res.append(-1)
else:
res.append(l[i+1])
return res
|
ce6151fe46b82f3425597613eba4946cef0c8e2e | daniel-reich/ubiquitous-fiesta | /SYmHGXX2P26xu7JFR_9.py | 335 | 3.734375 | 4 |
def number_groups(group1, group2, group3):
one = list(set(group1))
second = list(set(group2))
third = list(set(group3))
x = [one, second, third]
new_list = []
for i in x:
for a in i:
new_list.append(a)
print(new_list)
final = list(set([i for i in new_list if new_list.count(i) > 1]))
return sorted(final)
|
962a29e036ff4ce35c4d1cb3a8bb8fa7b1e7860e | daniel-reich/ubiquitous-fiesta | /ove5xwGAKfMxRmcbF_21.py | 113 | 3.640625 | 4 |
def match(s1, s2):
s1 = s1.lower()
s2 = s2.lower()
if s1 == s2:
return True
else:
return False
|
1bfa13d4e1882c0134ae059deee153b62ba55442 | daniel-reich/ubiquitous-fiesta | /mmiLWJzP3mvhjME7b_15.py | 978 | 3.609375 | 4 |
from abc import ABC, abstractmethod
class State(ABC):
def __call__(self, command):
if command == 'state':
return str(self)
if command == 'stop':
return 'accept' if self.is_final() else 'reject'
else:
return self.next_state(command)
@abstractmethod
def next_state(self, input):
raise NotImplementedError
def is_final(self):
return False
def __str__(self):
return type(self).__name__
class S0(State):
def next_state(self, input):
return {
0: self,
1: S1(),
}[input]
def is_final(self):
return True
class S1(State):
def next_state(self, input):
return {
0: S2,
1: S0,
}[input]()
class S2(State):
def next_state(self, input):
return {
0: S1(),
1: self,
}[input]
divisible = S0()
|
8064656d2daaad3a476c118d9add10c6ee74649f | daniel-reich/ubiquitous-fiesta | /KqR5XyJSJcJFnD5uF_15.py | 142 | 3.640625 | 4 |
def median(nums):
return round((nums[int(len(nums)/2)-1]+nums[int(len(nums)/2)])/2,1) if len(nums)%2==0 else nums[int((len(nums)+1)/2)-1]
|
9c9433069cd343825e4d530307c7e7c2b38676e8 | daniel-reich/ubiquitous-fiesta | /fmQ9QvPBWL7N9hSkq_17.py | 107 | 3.671875 | 4 |
def unstretch(word):
return word[0]+''.join(word[x] for x in range(1,len(word)) if word[x]!=word[x-1])
|
f43dc4ff6d1ad9e7a7a843008d8044a712957ea0 | daniel-reich/ubiquitous-fiesta | /hoxv8zaQJNMWJqnt3_24.py | 247 | 3.578125 | 4 |
def is_heteromecic(n):
if n % 2 != 0:
return False
else:
n = n // 2
return cur(n)
def cur(n,i=0):
if n - i < 0:
return False
elif n == i:
return True
else:
return cur(n-i,i+1)
|
b56a5dbabb8327ae7c3345eb50ac7eb4ac78b52e | daniel-reich/ubiquitous-fiesta | /6TJmj5gYEWBxPiuLD_13.py | 297 | 3.515625 | 4 |
def seating_students(lst):
ways = 0
n = lst.pop(0)
for s1 in range(1, n + 1):
if s1 in lst:
continue
if s1 < n - 1 and s1 + 2 not in lst:
ways += 1
if s1 % 2 == 1 and s1 < n and s1 + 1 not in lst:
ways += 1
return ways
|
c99943b96c5230aac119b0acfec021238c9e4196 | daniel-reich/ubiquitous-fiesta | /g6yjSfTpDkX2STnSX_5.py | 138 | 3.71875 | 4 |
def convert_to_hex(txt):
ascii_list = [ord(x) for x in txt]
hex_list = [hex(y)[2:] for y in ascii_list]
return ' '.join(hex_list)
|
3c8ed3e7a9ecc922ce632d7a77a050d46a6a9620 | daniel-reich/ubiquitous-fiesta | /NQToxLLFCjugHWBoZ_18.py | 167 | 3.53125 | 4 |
def sort_by_character(lst, n):
d = {}
for i in range(0,len(lst)):
d[lst[i][n-1]] = i
arr = []
for k in sorted(d):
arr.append(lst[d[k]])
return arr
|
35bc2ba2328ed4e2eee8b836a3b832163fd85f11 | daniel-reich/ubiquitous-fiesta | /uWW8cZymSkrREdDpQ_23.py | 222 | 3.640625 | 4 |
def sums_up(lst):
x = []
for a in range(1,len(lst)):
for b in range(a):
if lst[a]+lst[b] == 8:
x.append(sorted([lst[a],lst[b]]))
dict = {'pairs':x}
return dict
|
47152b2d8e424f3ea90b42caf479e7ea8515d65c | daniel-reich/ubiquitous-fiesta | /pyMScvcjbxG7rMcNT_3.py | 241 | 3.65625 | 4 |
def sum_list(lst):
if type(lst[0]) != int and len(lst) == 1:
return sum_list(lst[0])
if type(lst[0]) != int:
return sum_list(lst[0]) + sum_list(lst[1:])
if len(lst) == 1:
return lst[0]
return lst[0] + sum_list(lst[1:])
|
376c28af511355fd8a181b47f280d9785a55de7c | daniel-reich/ubiquitous-fiesta | /B2jcSh2RG4GpQYuBz_20.py | 174 | 3.703125 | 4 |
def is_valid_phone_number(txt):
c=""
for i in txt:
if i.isdigit():
c+=i
return len(c)==10 and "({}) {}-{}".format(c[:3],c[3:6],c[6:])==txt
|
083bd04e4328e19349df6da450ae748566efbace | daniel-reich/ubiquitous-fiesta | /49pyDP8dE3pJ2dYMW_16.py | 94 | 3.671875 | 4 |
def divisible_by_five(n):
result = False
if n%5 == 0:
result = True
return result
|
eeccf66e81a298f5675a5858044ab63b1290a451 | daniel-reich/ubiquitous-fiesta | /4me7LifXBwj5rhL4n_16.py | 185 | 3.71875 | 4 |
import math
def circle_or_square(rad, area):
perimeter = 4*math.sqrt(area)
circumference = 2 * 3.14 * rad
if circumference > perimeter:
return True
else:
return False
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.