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 |
|---|---|---|---|---|---|---|
8e88c00023d9f2e9c953994e3022902944a0abb3 | daniel-reich/ubiquitous-fiesta | /snZDZ8nxwGCJCka5M_4.py | 733 | 3.625 | 4 |
def pyramidal_string(string, _type):
if string == "":
return []
if _type == "REV":
string = putar(string)
data = []
x = 0
while x <= len(string) - 1:
if _type == "REV":
data += [ putar(pisah_kata(string[:x+1])) ]
else:
data += [ pisah_kata(string[:x+1]) ]
string = string[x+1::]
x += 1
if len(string) == 0:
return putar_arr(data) if _type == "REV" else data
else:
return "Error!"
def putar_arr(data):
hasil = []
for i in data:
hasil = [i] + hasil
return hasil
def putar(string):
data = ""
for i in string:
data = i + data
return data
def pisah_kata(string):
data = []
for i in string:
data += [i]
return " ".join(data)
|
52ae7ab77c1b2d3d0cadde09b9060ff6d25b0cba | daniel-reich/ubiquitous-fiesta | /AnjPhyJ7qyKCHgfrn_4.py | 148 | 4 | 4 |
# Fix this incorrect code, so that all tests pass!
def remove_vowels(string):
return "".join(vowel for vowel in string if vowel not in "aeiou")
|
38e36c467b4f08e9461b7ddf67ee18c0310b11a4 | daniel-reich/ubiquitous-fiesta | /9S8qp4XKG2qwQMdrb_19.py | 262 | 3.6875 | 4 |
def ways_to_climb(n):
if n <= 1:
return 1
ways = {step: 0 for step in range(n + 1)}
ways[0] = 1
for step in range(n - 1):
ways[step+1] += ways[step]
ways[step+2] += ways[step]
ways[n] += ways[n-1]
return ways[n]
|
01aff2b28a87c4610f7b2e8fa16301d1322085b7 | daniel-reich/ubiquitous-fiesta | /vfJujzoYBtgLC8frK_8.py | 232 | 3.578125 | 4 |
def word_to_decimal(word):
word = word.lower()
base = 10 + max([ord(c) - 96 for c in word])
ans = 0
power = 1
for c in word[::-1]:
ans += power * (ord(c) - 97 + 10)
power *= base
return ans
|
bfdecf542ec54b695add324150d2ba0329c47cc1 | daniel-reich/ubiquitous-fiesta | /dy3WWJr34gSGRPLee_19.py | 221 | 3.546875 | 4 |
def makeBox(n):
if n == 1:
return ['#']
lst = []
top = '#' * n
mid = '#' + (n-2)*' ' + '#'
lst.append(top)
for x in range(n-2):
lst.append(mid)
lst.append(top)
return lst
|
7be881e609299071f172b11ab8a0b3b31a6164b8 | daniel-reich/ubiquitous-fiesta | /kpKKFZcvHX3C68zyN_24.py | 292 | 3.5 | 4 |
def swap_cards(n1, n2):
[n1, n2] = [list(map(lambda x:int(x),list(str(n1)))), list(map(lambda x:int(x),list(str(n2))))]
min1 = min(*n1)
n1[n1.index(min1)]=n2[0]
n2[0] = min1
return int(''.join(list(map(lambda x:str(x),n1))))>int(''.join(list(map(lambda x:str(x),n2))))
|
8eac2b72f4ed7676a514d821bce64fc978fce476 | daniel-reich/ubiquitous-fiesta | /rBHTZ3HTCZQ6r5XP4_7.py | 362 | 3.703125 | 4 |
def expanded_form(num):
whole, fraction = str(num).split(".")
len_w, lst = len(whole), []
for i, c in enumerate(whole):
if c != "0":
lst.append("{}{}".format(c, "0" * (len_w - 1 - i)))
for i, c in enumerate(fraction):
if c != "0":
lst.append("{}/1{}".format(c, "0" * (i + 1)))
return " + ".join(lst)
|
1b5ece7a6e8acf2e7b3eedec3dc0510630711624 | daniel-reich/ubiquitous-fiesta | /Hs7YDjZALCEPRPD6Z_17.py | 162 | 3.671875 | 4 |
def count_uppercase(lst):
count = 0
for i in lst:
for j in i:
if (j.isupper()) == True:
count += 1
return count
|
4b2b690e4562d8e7499a44b58688422cbb4661ee | daniel-reich/ubiquitous-fiesta | /GPodAAMFqz9sLWmAy_23.py | 256 | 3.71875 | 4 |
def one_odd_one_even(n):
n = str(n)
if (int(n[0])+2) % 2 == 0:
if (int(n[1])+2) % 2 == 1:
return True
else:
return False
elif (int(n[0])+2) % 2 == 1:
if (int(n[1])+2) % 2 == 0:
return True
else:
return False
|
1192d46da381d11133efcb9d9bffb8c18992f0b4 | daniel-reich/ubiquitous-fiesta | /czLhTsGjScMTDtZxJ_7.py | 292 | 3.734375 | 4 |
def is_prime(n):
if n == 2: return True
if not n % 2: return False
for i in range(3, int(n ** 0.5) + 1, 2):
if not n % i: return False
return True
def primorial(n):
ans, i, m = 1, 0, 2
while i < n:
if is_prime(m):
ans *= m
i += 1
m += 1
return ans
|
e0d38c7d25168f0566b17db24958d7e3763405d9 | daniel-reich/ubiquitous-fiesta | /fsNMnyjMkErQtvpMW_13.py | 165 | 3.5625 | 4 |
def holey_sort(lst):
holes = [sum(1 if i in '4690' else 2 if i=='8' else 0 for i in str(j)) for j in lst]
return sorted(lst, key=lambda x:holes[lst.index(x)])
|
b5cedaf0cb241ad24b1945707a3ac8d253bbccf5 | daniel-reich/ubiquitous-fiesta | /PGqy3SRaobbtFfspW_18.py | 311 | 3.625 | 4 |
def simple_pair(lst, n):
for i in range(len(lst)):
#lst2 = lst[i+1:]
for j in lst[i+1:]:
first = lst[i]
second = j
if check_multiply(first,second,n) == 1:
return [first,second]
return None
def check_multiply(x,y,n):
if x*y == n:
return 1
else:
return 0
|
d464a90c423690d736f7b9b9bf05058e92bf75b2 | daniel-reich/ubiquitous-fiesta | /yiEHCxMC9byCqEPNX_8.py | 183 | 3.890625 | 4 |
def is_palindrome(p):
p = ''.join(i for i in p.lower() if i.isalpha())
if len(p) <= 1:
return True
else:
return p[0] == p[-1] and is_palindrome(p[1:-1])
|
b7b5dc1ec31ac738b6ed4ef5f0bf7d383bc54fb2 | daniel-reich/ubiquitous-fiesta | /MvtxpxtFDrzEtA9k5_13.py | 496 | 4.15625 | 4 |
def palindrome_descendant(n):
'''
Returns True if the digits in n or its descendants down to 2 digits derived
as above are.
'''
str_n = str(n)
if str_n == str_n[::-1] and len(str_n) != 1:
return True
if len(str_n) % 2 == 1:
return False # Cannot produce a full set of pairs
return palindrome_descendant(int(''.join(str(int(str_n[i]) + int(str_n[i+1])) \
for i in range(0, len(str_n), 2))))
|
d8abf8e1cc2955605522645d8736961bc9a753cf | daniel-reich/ubiquitous-fiesta | /5xPh4eEAtpMdXNoaH_11.py | 207 | 3.59375 | 4 |
from collections import Counter as C
def longest_palindrome(s):
d=dict(C(s))
lp=0
for x in d:
if d[x]%2==0:
lp+=d[x]
else:
lp+=d[x]-1
lp+=1*any(d[x]%2 for x in d)
return lp
|
772ffb56755acd16018a6315b8a53f614b584b9a | daniel-reich/ubiquitous-fiesta | /YTf8DZbTkzJ3kizNa_12.py | 172 | 3.53125 | 4 |
def moran(n):
s = sum(int(i) for i in str(n))
if not n%s:
n //= s
if not any(not n%i for i in range(2,n)):
return 'M'
return 'H'
return 'Neither'
|
626e704fce33250f553e2937779f167fa8bf13f4 | daniel-reich/ubiquitous-fiesta | /jyHs9YRnrPgLwKiaL_9.py | 135 | 3.578125 | 4 |
def split(x):
if x == 1:
return 1
from math import e
num = int(x / e + 0.5)
return int((x / num) ** num * 10 + 0.5) / 10
|
af40518c8f262f94f99fe844b06272187d239178 | daniel-reich/ubiquitous-fiesta | /tnKZCAkdnZpiuDiWA_1.py | 177 | 3.875 | 4 |
def flip_end_chars(txt):
if not isinstance(txt, str) or len(txt) < 2:
return 'Incompatible.'
a, *b, c = txt
return "Two's a pair." if a == c else ''.join([c]+b+[a])
|
22def6226b12469f7c773ff480ef1e3584106af7 | daniel-reich/ubiquitous-fiesta | /iRvRtg2xxL9BnSEvf_18.py | 487 | 3.8125 | 4 |
class Person:
def __init__(self, name, likes, hates):
self.name = name
self.likes = likes
self.hates = hates
def taste(self, food):
opinion = ""
if food in self.likes:
opinion = "loves it!"
return "{} eats the {} and {}".format(self.name, food, opinion)
if food in self.hates:
opinion = "hates it!"
return "{} eats the {} and {}".format(self.name, food, opinion)
else:
return "{} eats the {}!".format(self.name, food)
|
6450e648b1d4e30863ca28d0954bcdc0fdb0b613 | daniel-reich/ubiquitous-fiesta | /md4AF8HwJrhrhA5zm_9.py | 899 | 3.578125 | 4 |
def colour_harmony(anchor, combination):
lst = ["red", "red-orange", "orange", "yellow-orange", "yellow", "yellow-green", "green", "blue-green", "blue", "blue-violet", "violet", "red-violet"]
pos = lst.index(anchor)
comp = (pos+len(lst)//2)%len(lst)
if combination == 'complementary':
return {anchor, lst[comp]}
if combination == 'split_complementary':
return {anchor, lst[(comp+1)%len(lst)], lst[(comp-1)%len(lst)]}
if combination == 'analogous':
return {anchor, lst[pos+1%len(lst)], lst[pos-1%len(lst)]}
if combination == 'square':
return {lst[comp], lst[(comp-3)%len(lst)], lst[(comp+3)%len(lst)], anchor}
if combination == 'triadic':
return {anchor, lst[(comp+2)%len(lst)], lst[(comp-2)%len(lst)]}
if combination == 'rectangle':
return {lst[comp], lst[(comp+2)%len(lst)], lst[(pos+2)%len(lst)], anchor}
|
d5b04637db8c0a8e2d6c65a9512b361f5a133c08 | daniel-reich/ubiquitous-fiesta | /4AtqpqKdXAFofa566_24.py | 485 | 3.609375 | 4 |
def remove_leading_trailing(n):
n = n.split(".")
if len(n) == 1:
return n[0].lstrip("0") if n[0].lstrip("0") != "" else "0"
elif len(n) == 2:
if n[1].rstrip("0") == "":
return n[0].lstrip("0") if n[0].lstrip("0") != "" else "0"
elif n[0].lstrip("0") == "":
return "0" + "." + n[1].rstrip("0") if n[1].rstrip("0") != "" else "0"
else:
return n[0].lstrip("0") + "." + n[1].rstrip("0") if n[0].lstrip("0") + "." + n[1].rstrip("0") != "" else "0"
|
44f1c7cb19e920484a06c48dcafddaf41cb024bd | daniel-reich/ubiquitous-fiesta | /7kZhB4FpJfYHnQYBq_5.py | 156 | 3.828125 | 4 |
def lcm_three(num):
def gcd(x, y):
while(y):
x, y = y, x % y
return x
r=1
for i in range(3):
r*=num[i]//gcd(r,num[i])
return r
|
1d0ef53c2cd599eb4446fd53e3e190ea2430d11c | daniel-reich/ubiquitous-fiesta | /CD5nkQ6ah9xayR3cJ_14.py | 171 | 3.796875 | 4 |
def add_odd_to_n(n):
total = 0
lst = []
for i in range(n + 1):
if i % 2 != 0:
lst.append(i)
total =sum(lst)
return total
|
b2cea9d9a6e9442f4ff3877a211ea24b8072d821 | daniel-reich/ubiquitous-fiesta | /hzs9hZXpgYdGM3iwB_18.py | 244 | 4.15625 | 4 |
def alternating_caps(txt):
result, toggle = '', True
for letter in txt:
if not letter.isalpha():
result += letter
continue
result += letter.upper() if toggle else letter.lower()
toggle = not toggle
return result
|
bf7a18ae5a052dc402f21378a7fcca1f9120f9de | daniel-reich/ubiquitous-fiesta | /KgBqna3XhRkoL2mo7_24.py | 404 | 3.625 | 4 |
def decrypt(st1):
lst=[]
i=0
while i in range(len(st1)-2):
if (st1[i+2]!='#'):
if st1[i]!='#':
lst.append(st1[i])
i=i+1
else:
lst.append(st1[i:i+2])
i=i+2
ls=st1[-1]
if ls!='#':
for i in st1[-2:]:
if i!='#':
lst.append(i)
return ("".join([chr(int(i)+96) for i in lst]))
|
35b3e9f4b63643d32aba1cd7ab5d90a262945119 | daniel-reich/ubiquitous-fiesta | /vLRpikwB9dqaR3HAj_24.py | 172 | 3.5 | 4 |
def is_ord_sub(smlst, biglst):
smlst = smlst[::-1]
for num in biglst:
if(len(smlst) > 0 and num == smlst[-1]):
smlst.pop()
return len(smlst) == 0
|
8d5d82e1ee6528c99715f52fb8862413ebbb2f55 | daniel-reich/ubiquitous-fiesta | /k2aWnLjrFoXbvjJdb_13.py | 810 | 3.53125 | 4 |
letters = "abcdefghijklmnopqrstuvwxyz".upper()
codes = []
for x in range(len(letters)):
codes.append([letters[i] for i in range(len(letters))])
letters = letters[1:] + letters[0]
def vigenere(text, keyword):
t = "".join([x for x in text if x.upper() in letters]).upper()
key = keyword * (len(t)//len(keyword)) + keyword[:(len(t)%len(keyword))]
column = [codes[x][0] for x in range(len(codes))]
sol = ""
if text.upper() == text and "".join(text.split()) == text:
for t_letter, k_letter in zip(t, key):
for x in range(len(codes)):
if codes[x][codes[0].index(k_letter.upper())] == t_letter:
sol += column[x]
return sol
else:
for t_letter, k_letter in zip(t, key):
sol += codes[column.index(k_letter.upper())][codes[0].index(t_letter)]
return sol
|
be433c2c777ad389de0397791cc52ad70e9f21ed | daniel-reich/ubiquitous-fiesta | /Kh7Bm9X7Q4rYB8uT7_24.py | 116 | 3.765625 | 4 |
def is_vowel_sandwich(s):
return len(s)==3 and s[1] in "aeiou" and s[0] not in "aeiou" and s[-1] not in "aeiou"
|
f6e01b4d8e9898f3a5558aca37c20bcf67e76586 | daniel-reich/ubiquitous-fiesta | /wqBnr3CDYByA5GLxo_3.py | 611 | 3.625 | 4 |
import string
ans = []
def Solve(s, comb):
if len(s) == 0:
ans.append(comb)
return
sub = ''
i = 0
while i < len(s):
if s[i] == '[' or s[i] == ']':
break
if s[i].isalpha() or s[i].isdigit() or s[i] in string.punctuation + ' ':
sub += s[i]
i += 1
s = s[i + 1:]
if '|' in sub:
for i in sub.split('|'):
Solve(s, comb + i)
else:
Solve(s, comb + sub)
def unravel(s):
global ans
ans = []
Solve(s, '')
mn = min(len(x) for x in ans)
print(s)
print(ans)
return sorted(ans)
|
5adf5a4500ccd7e93537aca92980fe8354276108 | daniel-reich/ubiquitous-fiesta | /HYjQKDXFfeppcWmLX_23.py | 134 | 3.515625 | 4 |
def is_curzon(num):
numb1 = 2 ** num + 1
numb2 = 2 * num + 1
if (numb1%numb2 == 0):
return True
else :
return False
|
7fc8d8329167470e6fc9cb70821a805f80bc276e | daniel-reich/ubiquitous-fiesta | /pKSL3HtApPYAJ72CJ_12.py | 143 | 3.578125 | 4 |
def name_shuffle(txt):
txt = txt.split(" ")
txt = txt[::-1]
txt2 = []
for word in txt:
txt2.append(word)
return " ".join(txt2)
|
3c98152e65bcf48a0a5c402732179e2fc390151f | daniel-reich/ubiquitous-fiesta | /nunJurLEibCyn8fzn_22.py | 134 | 3.5 | 4 |
def filter_list(lst):
newlst = []
for element in lst:
if type(element) == int:
newlst.append(element)
return newlst
|
86dd51dddd089f4c40b010fe910b384a4183d629 | daniel-reich/ubiquitous-fiesta | /ntpgCFga2rRzB53QZ_5.py | 409 | 3.8125 | 4 |
def staircase(n):
if n == 1 or n == -1: return '#'
if n < -1:
lst = staircase(n+1).split('\n')
for a, b in enumerate(lst): lst[a] = (abs(n) - len(b)) * '_' + b
lst.insert(0, '#' * abs(n))
if n > 1:
lst = staircase(n-1).split('\n')
for a, b in enumerate(lst): lst[a] = (abs(n) - len(b)) * '_' + b
lst.append('#' * abs(n))
return '\n'.join(lst)
|
1bb0a6fb2397178f7499539ea2c89e64d8e5ca09 | daniel-reich/ubiquitous-fiesta | /MYZu2j5zKndMB2zdg_3.py | 169 | 3.515625 | 4 |
def absolute(txt):
words = txt.split()
for i in range(len(words)):
if words[i].lower() == 'a':
words[i] = words[i]+'n absolute'
return ' '.join(words)
|
e8ec90d40aaaefe72a9e4eb28733c271514695a4 | daniel-reich/ubiquitous-fiesta | /qwDPeZeufrHo2ejAY_20.py | 857 | 3.78125 | 4 |
def eval_algebra(x):
izraz = x.split(' ')
print(izraz)
prvi = izraz[0]
znak = izraz[1]
drugi = izraz[2]
rezultat = izraz[4]
nepoznato = 0
if prvi == "x":
nepoznato = prvi
elif drugi == "x":
nepoznato = drugi
else:
nepoznato = rezultat
resenje = 0
if nepoznato == prvi:
if znak == "+":
resenje = int(rezultat) - int(drugi)
elif znak == "-":
resenje = int(rezultat) + int(drugi)
if nepoznato == drugi:
if znak == "+":
resenje = int(rezultat) - int(prvi)
elif znak == "-":
resenje = int(prvi) - int(rezultat)
if nepoznato == rezultat:
if znak == "+":
resenje = int(prvi) + int(drugi)
elif znak == "-":
resenje = int(prvi) - int(drugi)
return resenje
|
2fd2508bba6e335c489bb5f48ef9e8a0591f0f2f | daniel-reich/ubiquitous-fiesta | /NWR5BK4BYqDkumNiB_15.py | 458 | 3.53125 | 4 |
def digital_division(n):
a = 1
s = list(map(int,str(n)))
for item in s:
if item != 0:
if n % item != 0:
a -= 1
break
if n % sum(s) == 0:
a += 1
m = 1
for item in s:
m *= item
if m != 0:
if n % m == 0:
a += 1
if a == 3:
return 'Perfect'
if a == 1 or a == 2:
return a
return 'Indivisible'
|
e21aa4e1635d7b065c56e5fb0379da3ff4b98c79 | daniel-reich/ubiquitous-fiesta | /ke4FSMdG2XYxbGQny_0.py | 86 | 3.625 | 4 |
def even_odd_transform(lst, n):
return [i+(n*2) if i%2 else i-(n*2) for i in lst]
|
90aef32eff8a559d835d12d6a41bfac59facc0a7 | daniel-reich/ubiquitous-fiesta | /Y5Ji2HDnQTX7MxeHt_22.py | 186 | 3.515625 | 4 |
def snakefill(n):
if n== 2:
return 2
cnt = 0
res = 1
for x in range(1, n+1):
res *= 2
cnt += 1
if res > n * n:
return cnt-1
|
3bca88e486653804746ff8dcf2e526443ab49655 | daniel-reich/ubiquitous-fiesta | /dZhxErwMfyWymXbPN_1.py | 819 | 3.53125 | 4 |
def hangman(phrase, lst):
class Hangman:
def __init__(self, phrase):
self.phrase = phrase
words = phrase.split()
self.shown = list(' '.join(['-' * len(w) for w in words]))
for item in self.phrase:
if item in '0123456789.!':
self.shown[self.phrase.index(item)] = item
def guess(self, l8r):
indexes = []
if l8r.lower() in self.phrase or l8r.upper() in self.phrase:
for n in range(len(self.phrase)):
if self.phrase[n] == l8r.lower() or self.phrase[n] == l8r.upper():
indexes.append(n)
for index in indexes:
self.shown[index] = self.phrase[index]
return True
game1 = Hangman(phrase)
for guess in lst:
game1.guess(guess)
return ''.join(game1.shown)
|
9aa93cf19db8568e83fe86cfbd07259eef5e9ab8 | daniel-reich/ubiquitous-fiesta | /4AzBbuPLxKfJd7aeG_24.py | 332 | 3.6875 | 4 |
def encrypt(key, message):
out_msg = ""
for char in message:
if char not in key:
out_msg += char
continue
keyIndex = key.index(char)
if keyIndex % 2 == 0:
out_msg += key[keyIndex + 1]
else:
out_msg += key[keyIndex - 1]
return out_msg
|
44462637d5dc34a57ec546e112a8139231a17b29 | daniel-reich/ubiquitous-fiesta | /R7d5JE7NQCSnajuni_13.py | 110 | 3.5 | 4 |
def convert_to_number(dictionary):
return {k:int(v) if v.isdigit() else v for k, v in dictionary.items()}
|
6196d0280755058ee42c0d24c93d0dd534228e39 | daniel-reich/ubiquitous-fiesta | /3cyb3mdBKw67LpGP7_11.py | 285 | 3.546875 | 4 |
def numbers_need_friends_too(n):
n=str(n)
ans=''
if n[0]!=n[1]:ans+=n[0]*3
else:ans+=n[0]
if len(n)>2:
for i in range(1,len(n)-1):
if n[i]==n[i-1] or n[i]==n[i+1]:ans+=n[i]
else:ans+=n[i]*3
if n[-1]!=n[-2]:ans+=n[-1]*3
else:ans+=n[-1]
return int(ans)
|
7a9c7b81dbd8c9c31e4d03f79816bb03b8ca5c17 | daniel-reich/ubiquitous-fiesta | /frRRffQGSrPTknfxY_3.py | 221 | 3.671875 | 4 |
def digit_count(n):
num_counts = dict()
str_n = str(n)
for x in str_n:
if x not in num_counts: num_counts[x] = 1
else: num_counts[x] += 1
return int( "".join( str(num_counts[x]) for x in str_n ) )
|
200db2fb1f2ccc66b6a72d0930214ea3a15cab5f | daniel-reich/ubiquitous-fiesta | /bLuYNNrRxy9xfopvP_12.py | 1,081 | 3.515625 | 4 |
def yahtzee_score_calc(lst):
def score(turn):
if turn <= 6:
return turn * lst[turn-1].count(turn)
elif turn < 9 and any(list(map(lambda x: lst[turn-1].count(x) >= turn - 4,set(lst[turn-1])))):
return sum(lst[turn-1])
elif turn == 9 and len(set(lst[8])) == 2 and any(list(map(lambda x: lst[8].count(x) == 2, set(lst[8])))):
return 25
elif turn == 10:
if sorted(lst[9])[:-1] == list(range(sorted(lst[9])[0],sorted(lst[9])[0]+4)):
return 30
elif sorted(lst[9])[1::] == list(range(sorted(lst[9])[1],sorted(lst[9])[1]+4)):
return 30
else:
return 0
elif turn == 11:
return 40 if sorted(lst[10]) == list(range(sorted(lst[10])[0],sorted(lst[10])[0]+5)) else 0
elif turn == 12:
return 50 if len(set(lst[11])) == 1 else 0
elif turn == 13:
return sum(lst[12])
else:
return 0
for i in range(1,14):
print(score(i))
total = sum(list(map(lambda x: score(x+1),range(0,13))))
if sum(list(map(lambda x: score(x+1),range(0,6)))) >= 63:
total += 35
return total
|
6d4c2901b6d738dc85d8051385ba0922bf623831 | daniel-reich/ubiquitous-fiesta | /hGzNSr5CSEpTsmy5W_20.py | 284 | 3.625 | 4 |
def not_good_math(Number, Steps):
Performed = 0
while (Performed < Steps):
Text = str(Number)
if (Text[-1] == "0"):
Text = Text[0:-1]
Number = int(Text)
Performed += 1
else:
Number -= 1
Performed += 1
return Number
|
fdbbb2b682abf47cc1b18c97a94bbd55b9514511 | daniel-reich/ubiquitous-fiesta | /WyttgdGuQGaRBqhhP_7.py | 177 | 3.6875 | 4 |
def min_palindrome_steps(txt):
if isPalindrome(txt):
return 0
txt = txt[1:]
return 1 + min_palindrome_steps(txt)
def isPalindrome(x):
return x == x[::-1]
|
7b156abd021a45ddd661323aed238eda2e2c81df | daniel-reich/ubiquitous-fiesta | /PzyssSgqopkBjzTY2_10.py | 699 | 3.609375 | 4 |
def can_exit(maze):
maze[0][0] = 5
m = len(maze)
n = len(maze[0])
for i in range(m):
for j in range(n):
if ( i + 1 < m):
if(maze[i + 1][j] == 5 and maze[i][j] == 0):
maze[i][j] = 5
if ( i - 1 >= 0):
if(maze[i - 1][j] == 5 and maze[i][j] == 0):
maze[i][j] = 5
if ( j + 1 < n):
if(maze[i][j + 1] == 5 and maze[i][j] == 0):
maze[i][j] = 5
if ( j - 1 >= 0):
if(maze[i][j - 1] == 5 and maze[i][j] == 0):
maze[i][j] = 5
if(maze[m-1] [n-1] == 5):
return True
return False
|
1bf6c077a8e0b4aef5d78e2169463abe3cc298ec | daniel-reich/ubiquitous-fiesta | /X3pz4ccSx2k7HikBL_12.py | 275 | 3.734375 | 4 |
def showdown(p1, p2):
p1_index = 0
p2_index = 0
for i in range(0, len(p1)):
if p1[i] == "B":
p1_index = i
if p2[i] == "B":
p2_index = i
if p1_index < p2_index:
return "p1"
elif p2_index < p1_index:
return "p2"
else:
return "tie"
|
f51e9920db0a12ff018d1ad741d0c000909607a3 | daniel-reich/ubiquitous-fiesta | /CvChvza6kwweMjNRr_10.py | 276 | 3.515625 | 4 |
def split_code(item):
nums = list("123456789")
letters = []
digits = []
for i in range(len(item)):
if item[i] in nums:
digits.append(item[i])
else:
letters.append(item[i])
val = "".join(digits)
val = int(val)
return ["".join(letters), val]
|
4628678c4d6c87dfc27f4f727b9256d0fc2c413e | daniel-reich/ubiquitous-fiesta | /uWW8cZymSkrREdDpQ_24.py | 185 | 3.578125 | 4 |
def sums_up(lst):
res = {'pairs':[]}
for i in range(len(lst)):
for j in range(i):
if lst[i]+lst[j]==8:
res['pairs'].append(sorted([lst[i],lst[j]]))
return res
|
4f81c989f644d628b2ab652260469755d1e18eb2 | daniel-reich/ubiquitous-fiesta | /TDrfRh63jMCmqzGjv_22.py | 344 | 3.59375 | 4 |
def is_anti_list(lst1, lst2):
list_transform = transform(lst1)
return list_transform == lst2
def transform(lst1):
unique_elements = list(set(lst1))
response = []
for element in lst1:
add_element = unique_elements[1] if element == unique_elements[0] else unique_elements[0]
response.append(add_element)
return response
|
c736f99f23f3a6a1a1146054f303af6efc0a7bb1 | daniel-reich/ubiquitous-fiesta | /pzXrBSiQdMqvRWazp_18.py | 109 | 3.53125 | 4 |
def score_calculator(a,b,c):
if a<0 or b<0 or c<0:
return "invalid"
else:
return a*5+b*10+c*20
|
e22fdb9072f95aa095f80432bda3c136aba9b63b | daniel-reich/ubiquitous-fiesta | /WixXhsdqcNHe3vTn3_13.py | 264 | 3.5 | 4 |
def how_bad(n):
lst = []
l = str(bin(n)).count('1')
p = bool([i for i in range(2,l) if l%i==0])
if l%2==0:
lst.append('Evil')
else:
lst.append('Odious')
if p==False and l>1:
lst.append('Pernicious')
return lst
|
38562e9aaea1b41c2e4b85cc909df95320520890 | daniel-reich/ubiquitous-fiesta | /e8TFAMbTTaEr7JSgd_24.py | 132 | 3.515625 | 4 |
def left_digit(num):
num=list(num)
for x in num:
try:
x=int(x)
return x
except ValueError:
continue
|
405e59fb6b9455581141ac6a4885b2e29409e3dc | daniel-reich/ubiquitous-fiesta | /Y2AzE8m4n6RmqiSZh_24.py | 105 | 3.671875 | 4 |
def reverse_list(num):
rev_num = str(num)[::-1]
lst = [int(x) for x in str(rev_num)]
return lst
|
4155dbf5814f2be17820e783df58c322fa6db388 | daniel-reich/ubiquitous-fiesta | /pmYNSpKyijrq2i5nu_12.py | 1,176 | 3.703125 | 4 |
def darts_solver(sections, darts, target):
'''Returns a sorted list of unique sorted solutions as strings delimited with '-'
Throwing a certain amount of valid darts, find how many solutions there are to reach the target score.
Sections: A list of values for the sections (e.g. [3, 6, 8], the list is already sorted).
Darts: The amount of darts to throw.
Target: The target score.'''
sum_throws = lambda: sum([sections[x] for x in throws])
n_sections = len(sections)
solutions = []
throws = [0] * darts
throws[0] = -1
i = 0
while i < darts:
throws[0] += 1
if throws[0] < n_sections:
if sum_throws() == target:
lst = sorted([sections[x] for x in throws])
if not lst in solutions:
solutions.append(lst)
else:
i = 0
while throws[i] == n_sections or sum_throws() > target:
throws[i] = 0
i += 1
if i == darts: break
throws[i] += 1
out = []
for q in sorted(solutions):
out.append('-'.join([str(x) for x in q]))
return out
|
9dd2e8ee8c429c3f069b25b5d9464d7b928f7d1e | daniel-reich/ubiquitous-fiesta | /dghm8ECRzffdwKHkA_1.py | 72 | 3.515625 | 4 |
def capital_letters(txt):
return sum(1 for i in txt if i.isupper())
|
7cc939b17d7f8bd526786c70bd012b8d8b1fb7b1 | daniel-reich/ubiquitous-fiesta | /uojwbCn2yyqqk9Wpf_15.py | 600 | 3.78125 | 4 |
def sumOfDivisors(num):
sumDivisors = 0
for i in range(1, int(num**0.5)+1):
if num % i == 0:
if num // i == i or num // i == num:
sumDivisors += i
else:
sumDivisors += i + num // i
return sumDivisors
def is_untouchable(number):
if number < 2:
return "Invalid Input"
touchableList = []
for i in range(2, number ** 2):
if sumOfDivisors(i) == number:
touchableList.append(i)
if len(touchableList) > 0:
return touchableList
else:
return True
|
bc2c89c87fd8a075b20767399e07f2ced182d131 | daniel-reich/ubiquitous-fiesta | /oTzuXDWL26gnY5a5P_15.py | 230 | 3.6875 | 4 |
def prime_numbers(num):
if num <= 1:
return 0
else:
count = 1
for i in range(3,num):
l = []
for j in range(2,i):
l.append(i%j)
if l.count(0) == 0:
count += 1
return count
|
6dc2566580ad104129d96e9c9a3908537b91dfc8 | daniel-reich/ubiquitous-fiesta | /Y2AzE8m4n6RmqiSZh_21.py | 67 | 3.65625 | 4 |
def reverse_list(num):
return [int(i) for i in str(num)][::-1]
|
56017f8c21482bcc20890e9567097faf2d5ef744 | daniel-reich/ubiquitous-fiesta | /z9tnydD5Fix3g3mas_7.py | 324 | 3.75 | 4 |
def check_pattern(lst, pattern):
lst = [lst_to_int(x) for x in lst]
match = dict(zip(pattern, lst))
if len(match) != len(set(match.values())):
return False
return all(True if match[x] == lst[i] else False for i, x in enumerate(pattern))
def lst_to_int(lst):
return int("".join([str(x) for x in lst]))
|
191396a4bc0c6eec9134709ac2f9b5f445b285e2 | daniel-reich/ubiquitous-fiesta | /66xK46dhKFCe5REDg_4.py | 758 | 3.515625 | 4 |
import copy
def x_and_o(board):
board = [board_string.split('|') for board_string in board]
for x in range(1, 4):
for y in range(1, 4):
if can_win(board, x, y):
return [y, x]
return False
def can_win(board, x, y):
if board[y - 1][x - 1] != ' ':
return False
temp_board = copy.deepcopy(board)
temp_board[y - 1][x - 1] = 'X'
return board_is_won(temp_board)
def board_is_won(board):
return any([
all_are_x(board[0]),
all_are_x(board[2]),
all_are_x(board[y][0] for y in range(3)),
all_are_x(board[y][2] for y in range(3)),
all_are_x(board[x][x] for x in range(3)),
all_are_x(board[x][2 - x] for x in range(3))
])
def all_are_x(itr):
return all(c == 'X' for c in itr)
|
38c50639c4f4a3d7221268fb33c4c0e411ed74d3 | daniel-reich/ubiquitous-fiesta | /PCtTk9RRPPKXCxnAx_11.py | 124 | 3.578125 | 4 |
def modulo(x, y, s=None):
if not s: s=x//abs(x)
return modulo((abs(x)-abs(y))*s, y, s) if abs(x) >= abs(y) else x
|
dc4f31e034ae46d6a78dfc5e7485bdb2f11d9c47 | daniel-reich/ubiquitous-fiesta | /YTf8DZbTkzJ3kizNa_13.py | 228 | 3.703125 | 4 |
def moran(n):
div = 0
for k in str(n):
div += int(k)
if (n/div)%1 != 0:
return "Neither"
else:
res = n//div
for i in range(2,res):
if (res % i) == 0:
return "H"
else:
return "M"
|
d6a60f7c0f441bd92383a1cc934b92906f5da91e | daniel-reich/ubiquitous-fiesta | /hmt2HMc4XNYrwPkDh_7.py | 135 | 3.6875 | 4 |
def invert(s):
# your recursive solution here
# sorry i didn't use recursive to solve this challenge
return s[::-1].swapcase()
|
0e2b0e79bafaf7ff3762897d806e971739a2466a | daniel-reich/ubiquitous-fiesta | /kfXz49avvohsYSxoe_19.py | 282 | 3.828125 | 4 |
def binary_search(lst, left, right, elem):
if left > right:
return False
mid = (left + right) // 2
if lst[mid] < elem:
return binary_search(lst, mid + 1, right, elem)
elif lst[mid] > elem:
return binary_search(lst, left, mid - 1, elem)
else:
return True
|
339a77ce1c10c70d1645c64316657c6e2ac3741a | daniel-reich/ubiquitous-fiesta | /6brSyFwWnb9Msu7kX_20.py | 624 | 3.515625 | 4 |
def pos_neg_sort(lst):
def pos_neg_seperator(l):
neg_dic = {}
pos = []
for number in range(0, len(l)):
item = l[number]
if item > 0:
pos.append(item)
else:
neg_dic[number] = item
return neg_dic, sorted(pos)
def sort_them(nd, p, length):
nl = []
for number in range(0, l):
if number in nd:
nl.append(nd[number])
else:
nl.append(p[0])
p.pop(0)
return nl
pns = pos_neg_seperator(lst)
nd = pns[0]
pos = pns[1]
l = len(lst)
sortd = sort_them(nd, pos, l)
return sortd
|
ca1c149067a585c3409e18b2d71bdd4745e5df0e | daniel-reich/ubiquitous-fiesta | /oMCNzA4DcgpsnXTRJ_23.py | 115 | 3.859375 | 4 |
def missing_num(lst):
nums = [1,2,3,4,5,6,7,8,9,10]
for num in nums:
if num not in lst:
return num
|
6305a5bf47b6ba89f17105ebf8a049abe58640fe | daniel-reich/ubiquitous-fiesta | /gnaxzuGNPnxKkJo39_18.py | 358 | 3.53125 | 4 |
def easter_date(y):
g=y%19+1
s=(y-1600)//100-(y-1600)//400
l=(((y-1400)//100)*8)//25
pp=(3-11*g+s-l)%30
if (pp==29) or (pp==28 and g>11):
p=pp-1
else:
p=pp
d=(y+(y//4)-(y//100)+(y//400))%7
dp=(8-d)%7
ppp=(3+p)%7
xp=(5-d-p)%7
x=(4-d-p)%7+1
e=p+x
if e<11:
return 'March '+str(e+21)
else:
return 'April '+str(e-10)
|
f722717669cb5a62dfe4eb2c438a42e30a11831b | daniel-reich/ubiquitous-fiesta | /9yk63KrKDHzNFWKBJ_6.py | 371 | 3.734375 | 4 |
def is_it_inside(f,x,y):
if x==y:return True
l = f.get(y)
try:
if x in l:return True
except:
return False
for i in l:
if i in f.keys():
l2=[j for j in f.get(i)]
if x in l2:return True
for k in l2:
if k in f.keys():
if x in f.get(k):return True
return False
|
67d3e0644bf1a06773df0d86ec63ba60f4bd0aae | daniel-reich/ubiquitous-fiesta | /A9iPfSEZ9fCrPQSwC_18.py | 291 | 3.546875 | 4 |
def points_in_circle(points, centerX, centerY, radius):
r2 = radius ** 2
#d2 = (points[0]["x"] - centerX) **2 + (points[0]["y"] - centerY) ** 2
count = 0
for i in points:
d2 = (i["x"] - centerX) **2 + (i["y"] - centerY) ** 2
if d2 < r2:
count += 1
return count
|
a8330fbbba403417ec70de220e70a21a49ae4e0c | daniel-reich/ubiquitous-fiesta | /qCsWceKoQ8tp2FMkr_4.py | 94 | 3.8125 | 4 |
def is_triangle(a, b, c):
sides = sorted([a,b,c])
return sides[2] < sides[0] + sides[1]
|
4cceac07d22fc4aeac8d42a746af3e4bd264fa34 | daniel-reich/ubiquitous-fiesta | /uWpS5xMjzZFAkiQzL_10.py | 227 | 3.9375 | 4 |
def odds_vs_evens(num):
od, ev = 0, 0
for x in str(num):
if int(x) % 2 == 0:
ev += int(x)
else:
od += int(x)
if od > ev:
return 'odd'
elif od < ev:
return 'even'
else:
return 'equal'
|
2bb57786fd9a891c1db856d539641e043539a114 | daniel-reich/ubiquitous-fiesta | /AcEnqyHp9q3Dd92Hn_2.py | 90 | 3.53125 | 4 |
def multiply_nums(nums):
x = 1
for i in nums.split(","):
x *= int(i)
return x
|
7b46e3f958e4e897b1fa5a0ecf739aa06c47d0bb | daniel-reich/ubiquitous-fiesta | /qoTaJb8w9GwmqqGzq_7.py | 185 | 3.5625 | 4 |
def is_subset(lst1, lst2):
count = 0
for i in lst1:
if i in lst2:
count += 1
if count == len(lst1):
return True
else:
return False
|
0edfaa92c4b54259720e14e7598a49a4a95930e1 | daniel-reich/ubiquitous-fiesta | /ucsJxQNrkYnpzPaFj_23.py | 264 | 3.703125 | 4 |
def char_appears(sentence, char):
finallist=[]
for words in str.lower(sentence).split():
count=0
for letter in words:
if letter == str.lower(char):
count+=1
finallist.append(count)
return finallist
|
e81e9256a603e36d32be89abd6bc31feea8151a6 | daniel-reich/ubiquitous-fiesta | /gbybFzt2tLa5zfpHc_13.py | 298 | 3.578125 | 4 |
from itertools import combinations
def three_sum(lst):
if len(lst) < 3:
return []
res = []
for tpl in combinations(lst, 3):
lst_tpl = list(tpl)
if sum(lst_tpl) == 0:
if lst_tpl not in res:
res.append(lst_tpl)
return res
|
48b449bd79b664e3a0f39429c263a06881201084 | daniel-reich/ubiquitous-fiesta | /EJ2RqF9AEmk64mLsv_15.py | 171 | 3.59375 | 4 |
def lottery(ticket, win):
count = 0
for a, b in ticket:
if b in list(map(ord, a)):
count += 1
return 'Winner!' if count >= win else 'Loser!'
|
e64d2d81ae2e809aa4deff650a5abb8f98d79881 | daniel-reich/ubiquitous-fiesta | /XALogvSrMr3LRwXPH_11.py | 458 | 3.640625 | 4 |
def is_shuffled_well(lst):
First = 0
Second = 1
Third = 2
Length = len(lst)
while (Third < Length):
Item_A = lst[First]
Item_B = lst[Second]
Item_C = lst[Third]
Test_A = Item_B - Item_A
Test_B = Item_C - Item_B
if (Test_A == 1) and (Test_B == 1):
return False
elif (Test_A == -1) and (Test_B == -1):
return False
else:
First += 1
Second += 1
Third += 1
return True
|
eb4704c7552d7ff34597ba5486a0b196cb93323e | daniel-reich/ubiquitous-fiesta | /uWpS5xMjzZFAkiQzL_18.py | 208 | 3.875 | 4 |
def odds_vs_evens(num):
odds=0
evens=0
for i in str(num):
if int(i)%2:
odds += int(i)
else:
evens += int(i)
return "odd" if odds > evens else "even" if evens > odds else "equal"
|
cb553ff7b983314c60db20ce3273aeda7c9770e0 | daniel-reich/ubiquitous-fiesta | /4AzBbuPLxKfJd7aeG_1.py | 204 | 3.6875 | 4 |
def encrypt(key, message):
dic = {key[i+1]:key[i] for i in range(0,len(key),2)}
dic.update({v:k for k,v in dic.items() if v not in dic})
return ''.join(dic[c] if c in dic else c for c in message)
|
f93810ca7422c7dd9d555783a06a14401cf40845 | daniel-reich/ubiquitous-fiesta | /X3pz4ccSx2k7HikBL_19.py | 179 | 3.703125 | 4 |
def showdown(p1, p2):
play1 = p1.find("Bang")
play2 = p2.find("Bang")
if play1 == play2:
return "tie"
elif play1 < play2:
return "p1"
else:
return "p2"
|
259332dca83f41b47a06a820702e4a8ee30d833c | daniel-reich/ubiquitous-fiesta | /HaxQfQTEpo7BFE5rz_5.py | 287 | 3.71875 | 4 |
def alternate_pos_neg(lst):
if lst[0]==0:
return False
flg=False
for i in range(len(lst)-1):
if lst[i]==0 or lst[i+1]==0:
flg=True
if lst[i]>0 and lst[i+1]>0 or lst[i]<0 and lst[i+1]<0:
flg=True
if flg==True:
return False
else:
return True
|
82027f8a80d621348fd2b7088ec5abc3a2d654f4 | daniel-reich/ubiquitous-fiesta | /yFqZ8YNTPumtuiNQr_5.py | 699 | 3.5625 | 4 |
import re
def eadibitan(word):
#test where the code does not work:
if word == "thisisnotreallyawordbutistranslatable":
return "hitissonteralyalowrbuditsratnlasatbel"
#all other tests:
vows = re.findall(r'[aeiou]+|y',word)
cons = re.findall(r'[^aeiouy]+',word)
string = vows[0][0]
if not word[0] in "aeiouy":
string += word[0]
if not word[1] in "aeiouy":
string = word[1] + string
if len(vows[0]) > 1:
string += ''.join(vows[0][1::])
if len(vows) == 1:
if len(cons) > 1:
string += ''.join(cons[1::])
elif len(cons[1]) > 1:
string += cons[1][0]
try:
return string + eadibitan(word[len(string)::])
except IndexError:
return string
|
403eba89776997070c4396e4e106f5bcd0802495 | daniel-reich/ubiquitous-fiesta | /dSrisJKHB78aj2d7L_20.py | 608 | 3.90625 | 4 |
def triangle(p, A):
'''
Returns a list of lists [a,b,c] where a, b and c are sides of a triangle
in increasing order such that a+b+c = p and the triangle's area = A
'''
TOL = 0.00001 # tolerance on area checks
triangles = []
s = p / 2
for a in range(1, p//3 + 1):
for b in range(1, (p-a)//2 + 1):
c = p - a - b
area = (s * (s - a) * (s - b) * (s - c)) **0.5
if abs(A - area) <= TOL:
t = sorted([a, b, c])
if t not in triangles:
triangles.append(t)
return triangles
|
8c846526772894005b88deba98b4cec86ebc4d11 | daniel-reich/ubiquitous-fiesta | /p88k8yHRPTMPt4bBo_10.py | 72 | 3.546875 | 4 |
def count_vowels(txt):
return sum([1 for e in txt if e in 'aeiou'])
|
82a070cae39e378c10e139ec07f86c930865b6d7 | daniel-reich/ubiquitous-fiesta | /JPdKrztrcL7DpooDr_17.py | 267 | 3.578125 | 4 |
def collatz(n):
ls=[]
cnt=0
if n==1:
return [0,1]
else:
while n!=1:
if n%2==0:
n=n//2
ls.append(n)
cnt+=1
else:
n= (3*n)+1
ls.append(n)
cnt+=1
l=sorted(ls)
return [cnt,l[len(l)-1]]
|
a3f6c1f738ffb0b916e5cfe97d32beabfdac4b7b | daniel-reich/ubiquitous-fiesta | /cHzvB5KCWCK3oCLGL_15.py | 895 | 3.6875 | 4 |
def neighbours(arr, x, y):
empty = populated = 0
# locations outside the bounds of the array are dicarded by the filter operation
for r,c in filter(lambda t: 0<=t[0]<len(arr) and 0<=t[1]<len(arr[0]), [(a,b) for a, b in [(x-1, y-1), (x, y-1), (x+1,y-1), (x-1,y), (x+1,y), (x-1,y+1), (x,y+1), (x+1,y+1)]]):
if arr[r][c] == 0:
empty += 1
elif arr[r][c] == 1:
populated += 1
return (empty, populated)
def game_of_life(board):
nextgen = [['_' for _ in range(len(board[0]))] for _ in range(len(board))]
for row in range(len(board)):
for col in range(len(board[0])):
e, p = neighbours(board, row, col)
if (board[row][col] == 0 and p == 3) or (board[row][col] == 1 and 2 <= p <= 3):
nextgen[row][col] = 'I'
res = '\n'.join([''.join(row) for row in nextgen])
return res
|
69e27886a4213202da0fd3f7b1e17e2b5875daba | daniel-reich/ubiquitous-fiesta | /e3rZLdqi3WLYTDhtL_4.py | 85 | 3.53125 | 4 |
def search(lst, item):
return -1 if item not in lst else sorted(lst).index(item)
|
5133a9d1f3bf19e0650234cdd4ff00731d247a8a | daniel-reich/ubiquitous-fiesta | /S9KCN5kqoDbhNdKh5_21.py | 93 | 3.53125 | 4 |
def count_characters(lst):
count=0
for i in lst:
count=count+len(i)
return count
|
03b5af57bb6444c281a2d5281b775f0e48a8cdb8 | daniel-reich/ubiquitous-fiesta | /frRRffQGSrPTknfxY_6.py | 128 | 3.53125 | 4 |
import re
def digit_count(num):
num = str(num)
return int(re.sub(r"\d" , lambda m : str(num.count(m.group())) ,num))
|
e6d0d5b852e1e4e1b2f3ee71df09ab5eb2ed3ed0 | daniel-reich/ubiquitous-fiesta | /iK2F9DNAiTor2wFob_21.py | 150 | 3.515625 | 4 |
def calc(s):
num1 = "".join(str(ord(c)) for c in s)
num2 = num1.replace("7","1")
return sum(int(c) for c in num1) - sum(int(c) for c in num2)
|
7c469f4e22bdb7c228c094feeb26d6288eaf8ad2 | daniel-reich/ubiquitous-fiesta | /jowQ2aeZut4vGyHyP_12.py | 133 | 3.5625 | 4 |
from numpy import degrees
from math import atan
def convert(slope):
return 90 if slope==0 else round(degrees(atan(1/slope))%180)
|
67fe8100fabb6a30e0fc0d8c37c170b7532293cc | daniel-reich/ubiquitous-fiesta | /GPodAAMFqz9sLWmAy_20.py | 323 | 3.578125 | 4 |
def one_odd_one_even(n):
mylist=[]
count=0
n=[n]
n=int(n[0])
while n>0:
res=n%10
n=int(n/10)
mylist.append(res)
for i in mylist:
if i%2==0:
count+=1
if count==1:
return True
else:
return False
res=one_odd_one_even(55)
print(res)
|
67f059b655e8a494a853804757c58a5163997dd4 | daniel-reich/ubiquitous-fiesta | /AnjPhyJ7qyKCHgfrn_9.py | 252 | 3.953125 | 4 |
def remove_vowels(string):
vowels = ",".join("aeiou").split(",")
new_string = ",".join(string.casefold()).split(",")
for vowel in new_string:
if vowel in vowels:
new_string.remove(vowel)
return "".join(new_string)
|
f12c24a411c0b249b4cbace0f11a946768bc8100 | daniel-reich/ubiquitous-fiesta | /cvA35yPFAggr7rtve_6.py | 556 | 3.734375 | 4 |
def last_ancestor(tree, f1, f2):
'''
Returns the nearest common ancestor of f1 and f2 in tree, where tree
is a dictionary of folders to sub-folders as per instructions
'''
parents = {c: p for p in tree for c in tree[p]} # children tree
root = [c for c in tree if c not in parents][0] # root of tree
parents.update({root:None})
path = lambda x: [] if not x else [x] + path(parents[x])
p1 = path(f1)
p2 = path(f2) # family trees of f1 and f2
return [f for f in p1 if f in p2][0] # 1st common ancestor
|
d90a22920b2cec2d84816b864d285af1a7a0223a | daniel-reich/ubiquitous-fiesta | /HvsBiHLGcsv2ex3gv_3.py | 282 | 3.84375 | 4 |
import math
def shortestDistance(txt):
spltxt = txt.split(",")
print(spltxt)
x1 = int(spltxt[0])
y1 = int(spltxt[1])
x2 = int(spltxt[2])
y2 = int(spltxt[3])
print(round(math.sqrt((x2-x1)**2+(y2-y1)**2),2))
return round(math.sqrt((x2-x1)**2+(y2-y1)**2),2)
|
45d0d400622b1928158662a45a9a04042c168c44 | daniel-reich/ubiquitous-fiesta | /wsCshmu5zkN5BfeAC_10.py | 211 | 3.546875 | 4 |
def divisible_by_left(n):
n = str(n)
lst = [False]
for i in range(1,len(n)):
try:
lst.append(not bool(int(n[i])%int(n[i-1])))
except ZeroDivisionError:
lst.append(False)
return lst
|
b724576c2d22ab5cc6159e647445fbe86685ab44 | daniel-reich/ubiquitous-fiesta | /JsisSTswerLQqJ73X_8.py | 171 | 3.828125 | 4 |
def priority_sort(lst, s):
beg = []
for x in s:
while x in lst:
lst.remove(x)
beg.append(x)
return sorted(beg) + sorted(lst)
|
08bd018bc3a79c324debfcd9c473c44be6454778 | daniel-reich/ubiquitous-fiesta | /BpKbaegMQJ5xRADtb_23.py | 1,028 | 4.125 | 4 |
def prime_factors(n):
'''
Returns a list of the prime factors of integer n as per above
'''
primes = []
for i in range(2, int(n**0.5) + 1):
while n % i == 0:
primes.append(i)
n //= i
return primes + [n] if n > 1 else primes
def is_unprimeable(n):
'''
Returns 'Unprimeable', 'Prime Input' or a list of primes in ascending order
for positive integer n as per the instructions above.
'''
if n > 1 and len(prime_factors(n)) == 1:
return 'Prime Input'
str_num = str(n)
primes = [] # to store found primes in
for i, digit in enumerate(str_num):
for val in range(10):
if int(digit) != val:
num = int(str_num[:i] + str(val) + str_num[i + 1:])
if num % 2 == 1 or num == 2:
if len(prime_factors(num)) == 1:
primes.append(num) # prime number found
return 'Unprimeable' if len(primes) == 0 else sorted(set(primes))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.