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
80f3767db5823cd3a8bee545344d94e9395c855c
lafleur82/python
/pirate_bartender.py
1,413
3.84375
4
import random #pirate bartender questions = { "strong": "Do ye like yer drinks strong? ", "salty": "Do ye like it with a salty tang? ", "bitter": "Are ye a lubber who likes it bitter? ", "sweet": "Would ye like a bit of sweetness with yer poison? ", "fruity": "Are ye one for a fruity finish? " } ingredients = { "strong": ["glug of rum", "slug of whiskey", "splash of gin"], "salty": ["olive on a stick", "salt-dusted rim", "rasher of bacon"], "bitter": ["shake of bitters", "splash of tonic", "twist of lemon peel"], "sweet": ["sugar cube", "spoonful of honey", "splash of cola"], "fruity": ["slice of orange", "dash of cassis", "cherry on top"] } def which_drink(flavors): answers = {} for k in flavors: answer = str(input(flavors[k])) if answer == "yes" or answer == "y": answers[k] = True elif answer == "no" or answer == "n": answers[k] = False else: print("Yes/y or No/n required.") print("\n") return answers def make_drink(flavors): drink = "" for i, k in enumerate(flavors): if flavors[k] is True: drink += random.choice(ingredients[k]) + ", " drink = drink[:-2] #remove trailing comma return drink while True: print(make_drink(which_drink(questions))) if str(input("Another? (yar or nay): ")) != 'yar': break
97576ccd0e9995ca4700b11659ca4ebc9f87fc59
4teraflops/Grokaem_algoritmy
/04_quick_sort.py
728
4.03125
4
def quicksort(arr): # Быстрая сортировка массива if len(arr) < 2: # Базовый случай. Массивы с 0 и с 1 элементом уже "отсоритрованы" return arr else: # рекурсивный случай pivot = arr[0] # Опорный элемент less = [i for i in arr[1:] if i <= pivot] # Подмассив всех элементов, меньших опорного greater = [i for i in arr[1:] if i > pivot] # подмассив всех элементов, больших опорного return quicksort(less) + [pivot] + quicksort(greater) print(quicksort([19, 56, 78, 11, 1, 98, 656, 4, 4, 8, 56, 45]))
8763f2691acce2296592481e302c279a4ccf0be7
CANYOUFINDIT/data_structure
/数据结构与算法/二分查找.py
744
3.75
4
# coding:utf-8 # 二分查找,只适用于有序数列,时间复杂度O(logn) def binary_search(list, item): # low和high用于跟踪要在其中查找的列表部分 low = 0 high = len(list) - 1 # 只要范围没有缩小到只包含一个元素 while low <= high: # 如果(low + high)不是偶数,Python自动将mid向下圆整。 mid = (low + high)/2 guess = list[mid] # 找到了元素 if guess == item: return mid # 猜的数字大了 if guess > item: high = mid - 1 # 猜的数字小了 else: low = mid + 1 # 没有指定元素 return None my_list = range(1, 100) print binary_search(my_list, 55)
d4a5c8d36c25c30a0584c51420267c4393481d29
rohitdewani/TwitterAlarmClock
/twitterAlarm.py
2,359
3.5625
4
#!/usr/bin/python3 # # twitterAlarm.py # # By Andy Sayler (www.andysayler.com) # April 2013 # # A basic program for counting tweets matching the provided search # query and triggering the playing of an alarm.wav file when the count # exceeds the provided threshold # # Note: Has some limits (max count of 100, no auth, etc) # Std Library Imports import sys import argparse import time import subprocess import urllib.request as request import urllib.parse as parse import json # Constants TIMEOUT = 10 # in seconds EXIT_FAILURE = -1 EXIT_SUCCESS = 0 # Uses Version 1.0 of the Twitter Search API: # https://dev.twitter.com/docs/api/1/get/search APIURL = "http://search.twitter.com/search.json" MAXQLENGTH = 1000 # Max 1000 for Twitter Search API RCOUNT = 100 # Max 100 for Twitter Search API ENCODING = 'utf-8' RESULTSKEY = 'results' # A function to query the search API and count the results def countTweets(query): queryEnc = parse.quote(query) if(len(queryEnc) > MAXQLENGTH): sys.stderr.write("Query Too Long") return EXIT_FAILURE url = APIURL + "?q=" + queryEnc + "&rpp=" + str(RCOUNT) res = request.urlopen(url) resData = res.read() resStr = resData.decode(ENCODING) resDec = json.loads(resStr) return len(resDec[RESULTSKEY]) # Setup Argument Parsing parser = argparse.ArgumentParser(description='Sound alarm when N tweets are detected') parser.add_argument('query', type=str, help='Twitter search query') parser.add_argument('count', type=int, help='Tweet threshold to sound alarm (max 99)') # Parse Arguments args = parser.parse_args() query = args.query threshold = args.count # Loop until threshold is reached cnt = countTweets(query) while(cnt < threshold): time.sleep(TIMEOUT) cnt = countTweets(query) if(cnt < 0): sys.stderr.write("countTweets returned error\n") break; sys.stdout.write("There are " + str(cnt) + " Tweets that match " + query + "\n") sys.stdout.write("Alarm will" + (" not " if (cnt < threshold) else " ") + "sound\n") # Sound alarm if threshold has been reached if(cnt >= threshold): p = subprocess.Popen(["aplay", "alarm.wav"]) while(p.poll() == None): time.sleep(1) # Exit on a happy note sys.exit(EXIT_SUCCESS) else: # Or not... sys.exit(EXIT_FAILURE)
02acbf492948ebb3969ce14bd5b2c9404ca2118a
daniel-reich/ubiquitous-fiesta
/es6qJTs5zYf8nEBkG_6.py
1,257
3.609375
4
def get_slope(pt1,pt2): (pt1x , pt1y) = pt1 (pt2x , pt2y) = pt2 if (pt2y - pt1y) == 0: return 1 slope = (pt2x - pt1x)/(pt2y - pt1y) return slope ​ def is_midpt_90_deg(pt1,pt2,pt3): slope1 = get_slope(pt1,pt2) slope2 = get_slope(pt2,pt3) if slope1 is None or slope2 is None: return False if (slope1 == 1 and slope2 == 0) \ or (slope1 == 0 and slope2 == 1): return True if (slope2 != 0 and slope1 == 1/-(slope2)) \ or (slope1 != 0 and slope2 == 1/-(slope1)): return True return False ​ def getPoint(value): try: pt_temp = value.replace("(","") \ .replace(")","") \ .replace(" ","") \ .split(',') pt = (int(pt_temp[0]) , int(pt_temp[1])) return pt except: return None def is_rectangle(coordinates): if len(coordinates) < 4: return False points = [] for coord in coordinates: tempPt = getPoint(coord) if tempPt is None: return False points.append(tempPt) i = 0 if is_midpt_90_deg(points[i],points[i+1],points[i+2]) \ and is_midpt_90_deg(points[i+1],points[i+2],points[i+3]) \ and is_midpt_90_deg(points[i+2],points[i+3],points[i]): return True return False
f27d6b8e4eb55bac0789818788e91a9578c410fd
daniel-reich/ubiquitous-fiesta
/g6yjSfTpDkX2STnSX_19.py
149
3.890625
4
def convert_to_hex(txt): thing = [hex(ord(char)) for char in txt] hexStr = "".join(char[2:]+ " " for char in thing) return hexStr[:-1]
074f936e918b85a0b3ed669bb60f0d02d7a790db
daniel-reich/ubiquitous-fiesta
/PLdJr4S9LoKHHjDJC_22.py
909
4.3125
4
# 1-> find if cube is full or not, by checking len of cube vs len of current row. ​ # 2-> calculate the missing parts in current row, by deducting the longest len of row vs current row. ​ # 3-> if we have missing parts return it. ​ # 4-> if we don't have missing parts, but our len of cube is smaller than our longest row. then that means we have a non-full cube. ​ def identify(*cube): totalMissingParts = 0 for row in range(len(cube)): maxLengthOfaRow = len(max([i for i in cube])) # Non-Full is True if len(cube) < maxLengthOfaRow or len(cube[row]) < maxLengthOfaRow: currentMissingParts = maxLengthOfaRow - len(cube[row]) totalMissingParts += currentMissingParts if totalMissingParts: return "Missing {}".format(totalMissingParts) else: if len(cube) < maxLengthOfaRow and not totalMissingParts: return "Non-Full" else: return "Full"
85500269ddf322186da7058d9bc924f5cc733fbb
daniel-reich/ubiquitous-fiesta
/6pEGXsuCAxbWTRkgc_21.py
227
3.671875
4
def loves_me(n): new = "" for i in range(n - 1): if i % 2 == 0: new += "Loves me, " else: new += "Loves me not, " if n % 2 == 0: new += "LOVES ME NOT" else: new += "LOVES ME" return(new)
65304bc83b070681fed43326ff3c76bd75696d37
daniel-reich/ubiquitous-fiesta
/djLTSAc6h4bt6ehWu_10.py
192
3.53125
4
import re def camelCasing(txt): if len(txt) == 0: return txt lst = re.split("[_\s]", txt) result = lst[0].lower() for word in lst[1:]: result += word.title() return result
459461c1bb4a51e680ab455d2985b4849ee3061d
daniel-reich/ubiquitous-fiesta
/G2QnBrxvpq9FacFuo_23.py
200
3.6875
4
def possible_path(lst): for i, l in enumerate(lst): if i in range(1, len(lst)-1): if type(l) == int: if str(lst[i-1])+str(lst[i+1]) != "HH": return False return True
2950192f84c4b16ace89e832e95300b7b58db078
daniel-reich/ubiquitous-fiesta
/ZdnwC3PsXPQTdTiKf_6.py
241
4.21875
4
def calculator(num1, operator, num2): if operator=='+': return num1+num2 if operator=='-': return num1-num2 if operator=='*': return num1*num2 if operator=='/': return "Can't divide by 0!" if num2==0 else num1/num2
68fef4c3d2d8164fb02ae67bc7603606a7709797
daniel-reich/ubiquitous-fiesta
/H7Z8enQWipfBMXTx7_21.py
148
3.6875
4
def fib_str(n, f): # Your recursive implementation of the code. if n == 2: return ", ".join(f) return fib_str(n-1, f + [f[-1] + f[-2]])
1d8be8c98af762b92b921416d091cdd435c3d026
daniel-reich/ubiquitous-fiesta
/z3wYnBQPgBTzy87WA_7.py
269
3.5
4
import numpy as np def rps(s1, s2): if (s1 == "paper" and s2 == "rock") or (s1 == "rock" and s2 == "scissors") or (s1 =="scissors" and s2 =="paper"): return "Player 1 wins" elif s1 == s2: return "TIE" else: return "Player 2 wins"
58e4e5464bd8cd998b2d480c9ff74da9635c7f0d
daniel-reich/ubiquitous-fiesta
/stAFzKqQnWHztzrAW_13.py
126
3.546875
4
def add_nums(nums): n_splt = nums.split(",") n_int = [] for i in n_splt: n_int.append(int(i)) return sum(n_int)
8ce03771e2cb46e9849f8b79cab18daa11409d03
daniel-reich/ubiquitous-fiesta
/eAnhzXPeGbobqk2P2_5.py
479
3.734375
4
def century(year): if year == 1000: return "10th century" elif year in range(1001,1100): return "11th century" elif year in range(1100,1200): return "12th century" elif year in range(1500,1600): return "16th century" elif year in range(1700,1800): return "18th century" elif year in range(2001,2100): return "21st century" elif year in range(1600,1700): return "17th century" elif year in range(1900,2001): return "20th century"
57fc2b657fc291816c34c85760c6a8b57c3d6677
daniel-reich/ubiquitous-fiesta
/suhHcPgaKdb9YCrve_24.py
311
4.1875
4
def even_or_odd(s): evenSum=0 oddSum=0 for i in s: if int(i)%2==0: evenSum+=int(i) else: oddSum+=int(i) if evenSum>oddSum: return "Even is greater than Odd" if evenSum<oddSum: return "Odd is greater than Even" if evenSum==oddSum: return "Even and Odd are the same"
0e35b3b8d40ce944e5289c3108061fb4552ebb5e
daniel-reich/ubiquitous-fiesta
/7kZhB4FpJfYHnQYBq_4.py
174
3.765625
4
def lcm_three(num): i = max(num) while True: if(i % num[0] == 0 and i % num[1] == 0 and i % num[2] == 0): print(i) #break return i i = i + 1
a7a0b797befc238f247d31f90f77b608d3d475b5
daniel-reich/ubiquitous-fiesta
/tDswMNY7X9h7tyTS4_3.py
202
3.546875
4
def pascals_triangle(n): trow, ans = [1], [1] y = [0] for x in range(1, n): trow=[left+right for left,right in zip(trow+y, y+trow)] for i in trow: ans.append(i) return ans
f576dc4d2d7979340158c2b232748e7f9d65a053
daniel-reich/ubiquitous-fiesta
/ecSZ5kDBwCD3ctjE6_8.py
106
3.71875
4
def find_smallest_num(lst): sm = lst[0] for num in lst: if num < sm: sm = num return sm
a7f3da87a64dc326237d82e24256ffe21e91b46a
daniel-reich/ubiquitous-fiesta
/GC7JWFhDdhyTsptZ8_22.py
481
3.71875
4
def sexy_primes(n, limit): it = 5 lst = [] while it < limit: if isPrime(it): check = True primes = [it] it2 = it + 6 while check and len(primes) < n: if isPrime(it2) and it2 < limit: primes.append(it2) it2 += 6 else: check = False if check: lst.append(tuple(primes)) it += 1 return lst def isPrime(n): for i in range(2, n): if n%i == 0: return False return True
d4f6f6d97e54897d01462002ed9bcbf5e68aa97e
daniel-reich/ubiquitous-fiesta
/czLhTsGjScMTDtZxJ_21.py
311
3.625
4
import numpy def primorial(n): primes = [] k = n*n if n>2 else 2 for possiblePrime in range(2, n+k): isPrime = True for num in range(2, possiblePrime): if possiblePrime % num == 0: isPrime = False if isPrime: primes.append(possiblePrime) return numpy.prod(primes[:n])
6d6aed10d9f2810041162239b1afbd65512c45c8
daniel-reich/ubiquitous-fiesta
/ZWEnJEy2DoJF9Ejqa_4.py
294
3.53125
4
def edabit_in_string(txt): edabit = list("edabit") holder = [] counter = 0 for char in range(len(txt)): if txt[char] == edabit[counter]: holder.append(txt[char]) counter +=1 if counter == len(edabit): break return "YES" if holder == edabit else "NO"
e33eedc7a49fc32b55e832f4cb2b96cafbec9b17
daniel-reich/ubiquitous-fiesta
/eoK63mG5tJDu439nJ_4.py
441
3.640625
4
def canChain(w1, w2): l1, l2 = len(w1), len(w2) if abs(l1 - l2) > 1: return False if l1 == l2: return sum(1 if w1[i] != w2[i] else 0 for i in range(l1)) == 1 if l2 > l1: return sum(1 if w2[i] not in w1 else 0 for i in range(l2)) <= 1 return sum(1 if w1[i] not in w2 else 0 for i in range(l1)) <= 1 ​ def isWordChain(words): return all(canChain(w1, w2) for w1, w2 in zip(words, words[1:]))
da4ae9404e8a65690430f00f07abf884b6379034
daniel-reich/ubiquitous-fiesta
/mz7mpEnMByAvBzMrc_4.py
397
4
4
def power_of_two(num): #mediocre code way if num == 0: return False elif num == 1 or num == 2: return True n, p = 2, 1 while n < num: n **= p if n == num: return True elif n > num: return False n = 2 p += 1 return False def power_of_two(num): return num != 0 and (num & (num - 1) == 0)
ed06dec35d1b15b9c099721218cacde291f93819
daniel-reich/ubiquitous-fiesta
/YSTk5RMQQeocbAteg_4.py
112
3.5
4
def tetra(n): number = 0 for value in range(1, n+1): number += sum(range(1, value+1)) return number
336f18d1e01cd899d5d60ebf385c1c173e448d48
daniel-reich/ubiquitous-fiesta
/fRZMqCpyxpSgmriQ6_24.py
177
3.5
4
def sorting(s): l = "".join(filter(lambda x: x.isalpha(), sorted(sorted(s, reverse=True), key=str.lower))) n = "".join(i for i in sorted(s) if i.isdigit()) return l + n
189ec35e6d0ad7f773ffd43c103872cb3e457845
daniel-reich/ubiquitous-fiesta
/58DYAThA2dxnAsMpL_24.py
175
3.59375
4
def integer_boolean(n): new_list = [] for i in range(len(n)): if n[i] == '1': new_list.append(True) else: new_list.append(False) return new_list
7046d75ebc168d17dff7fe84912d1a3a4159f785
daniel-reich/ubiquitous-fiesta
/cGaTqHsPfR5H6YBuj_23.py
172
3.515625
4
def make_sandwich(i, f): nl = [] for x in i: if x in f: nl.extend(['bread', x, 'bread']) else: nl.append(x) return nl
2f2304ca5c22f5215109bfb5a373a5710706c695
daniel-reich/ubiquitous-fiesta
/snZDZ8nxwGCJCka5M_18.py
850
3.515625
4
import math ​ def equation(n): return ((n+1)*(n)) // 2 ​ def equation2(n,k): return (n*k) - equation(k) ​ def join_strings(letters): if len(letters) > 1: k = [char + " " for char in letters[:-1]] join = ''.join(k) return join + letters[-1] else: return letters ​ def pyramidal_string(string, _type): if string == "": return [] elif len(string) == 1: return [string] n = (1+math.sqrt(1+(8*len(string))))/ 2 if (n).is_integer(): n = int(n) lst = [] if _type == "REG": for i in range(0,n): lst.append(string[equation(i):equation(i+1)]) else: for i in range(0,n): lst.append(string[equation2(n,i):equation2(n,i+1)]) lst = list(map(lambda x: join_strings(x),lst)) lst.remove("") return lst else: return "Error!"
d776981fb784fb4cd9f30f166f98f3d94be59d0e
daniel-reich/ubiquitous-fiesta
/arobBz954ZDxkDC9M_8.py
166
3.90625
4
def next_prime(num): while 1: if is_prime(num): return num else: num += 1 def is_prime(num): return all([num % i != 0 for i in range(2, num, 1)])
80fa64ccf56f3794ab42464d6ffbca33d782031a
daniel-reich/ubiquitous-fiesta
/pAFxfge35bT3zj4Bs_24.py
151
3.78125
4
def area_shape(base, height, shape): area =() if shape == "triangle": area = 0.5*base*height else: area = base*height return area
4a28f8efa11d6d5b7d0b464d6ea015332e537cbc
daniel-reich/ubiquitous-fiesta
/yiEHCxMC9byCqEPNX_12.py
200
3.921875
4
def is_palindrome(p): # your recursive solution here A=[x.lower() for x in p if x.isalpha()] if len(p)<2: return True else: return A[0]==A[-1] and is_palindrome(''.join(A[1:-1]))
3e4564a96edd4c18a9f5f50a8e037469cc2add27
daniel-reich/ubiquitous-fiesta
/Fw4fFSnTJfCsPBJ5u_16.py
188
3.6875
4
def how_many_missing(lst): if len(lst)==0: return 0 else: lst1=[] for i in range(min(lst),max(lst)+1): if i not in lst: lst1.append(i) return len(lst1)
2260ac154ddd3a850f94292077a14b21d957be39
daniel-reich/ubiquitous-fiesta
/2JHYavYqynX8ZCmMG_7.py
125
3.515625
4
def ascii_sort(lst): l=[sum(c) for c in [list(map(lambda y:ord(y),list(x))) for x in lst]] return lst[l.index(min(l))]
3c78f7c85f1d7af8ca85c62e6bdc0c502aaeaab4
daniel-reich/ubiquitous-fiesta
/EJRa8efMPoCwzLNRW_21.py
533
3.640625
4
def dakiti(sentence): started_list = sentence.split(' ') orded_list = [] numbers = [] for item in started_list: for number in item: if number.isdigit(): numbers.append(number) numbers.sort() for loop in numbers: for item in started_list: if loop in item: fitem = item.replace(loop,'') orded_list.append(fitem) final = '' for item in orded_list: final += item final += ' ' return final[:-1]
8f6185ab2f870037bf42c3a3377bb4237335e5e4
daniel-reich/ubiquitous-fiesta
/r8jXYt5dQ3puspQfJ_5.py
165
3.75
4
def split(txt): def is_vowel(let): return let in 'aieou' return ''.join([let for let in txt if is_vowel(let)] + [let for let in txt if not is_vowel(let)])
e6960fd8d232f73cbf792483d378eab0da1309b0
daniel-reich/ubiquitous-fiesta
/2TF3FbDiwcN6juq9W_19.py
2,533
3.734375
4
def days_until_2021(date): class Date: def is_leapyear(year): if year %4 == 0: if year % 100 == 0: if year % 400 == 0: return True return False return True return False def __init__(self, date): self.date = date date = [int(i) for i in date.split('/')] self.month = date[0] self.day = date[1] self.year = date[2] self.ly = Date.is_leapyear(self.year) def days_till(self, other): months = {1: 31, 2: [28, 29], 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} if self.year == other.year: selfdays = self.day for month in range(1, self.month): if month == 2: if self.ly == True: selfdays += months[month][1] else: selfdays += months[month][0] else: selfdays += months[month] otherdays = other.day for month in range(1, other.month): if month == 2: if other.ly == True: otherdays += months[month][1] else: otherdays += months[month][0] else: otherdays += months[month] if otherdays < selfdays: return False else: return otherdays - selfdays else: if self.year > other.year: return False selfdays = self.day for month in range(1, self.month): if month == 2: if self.ly == True: selfdays += months[month][1] else: selfdays += months[month][0] else: selfdays += months[month] if self.ly == True: diff = 366 - selfdays else: diff = 365 - selfdays for year in range(self.year + 1, other.year): if Date.is_leapyear(year) == True: diff += 366 else: diff += 365 for month in range(1, other.month): if month == 2: if other.ly == True: diff += months[month][1] else: diff += months[month][0] else: diff += months[month] diff += other.day return diff date1 = Date(date) date2 = Date('1/1/2021') days_till = date1.days_till(date2) if days_till == 1: return '1 day' else: return '{} days'.format(days_till)
802971e3e9e85cec08781127e9d65c98a31f1a9a
daniel-reich/ubiquitous-fiesta
/Es985FEDzEQ2tkM75_20.py
257
3.578125
4
def caesar_cipher(text, key): alphabet = "abcdefghijklmnopqrstuvwxyz" ting = '' for i in text: if i in alphabet: ind = alphabet.find(i)+key if ind>25: ind -= 26 ting+=alphabet[ind] else: ting+=i return ting
11863befa3ef87581407e9ce2ca4f64f42b3793c
daniel-reich/ubiquitous-fiesta
/uWpS5xMjzZFAkiQzL_16.py
258
3.9375
4
def odds_vs_evens(num): odd = sum([int(i) for i in str(num) if int(i) % 2 == 1]) even = sum([int(i) for i in str(num) if int(i) % 2 == 0]) if odd == even: return 'equal' elif odd > even: return 'odd' elif even > odd: return 'even'
7488ac68b03c3f95b28c8907c927700f3d33db0e
daniel-reich/ubiquitous-fiesta
/NebFhjXTn8NEbhYXY_11.py
114
3.703125
4
def divisible(num): remainder = num % 100 if remainder == 0: c = True else: c = False return c
fb4926915ccc29ef6f9ae7be452e9d423b60bde7
daniel-reich/ubiquitous-fiesta
/oaN8o42vuzsdnCf4x_4.py
598
3.609375
4
scores = { 'A': 1, 'B': 3, 'C': 3, 'D': 2, 'E': 1, 'F': 4, 'G': 2, 'H': 4, 'I': 1, 'J': 8, 'K': 5, 'L': 2, 'M': 3, 'N': 1, 'O': 1, 'P': 3, 'Q': 10, 'R': 1, 'S': 1, 'T': 1, 'U': 1, 'V': 4, 'W': 4, 'X': 8, 'Y': 4, 'Z': 10 } ​ def best_words(lst): highestScore = 0 highestScorers = [] for w in lst: score = 0 for c in w: score += scores[c.upper()] if score == highestScore: highestScorers.append(w) elif score > highestScore: highestScore = score highestScorers.clear() highestScorers.append(w) return highestScorers
ce2d4588f129c162d4566e9926268ab63707f221
daniel-reich/ubiquitous-fiesta
/ivWdkjsHtKSMZuNEc_23.py
630
3.6875
4
import re def find_shortest_words(txt): txt = re.sub('[^A-Za-z ]+', '', txt).lower().replace(" ", " ").split(" ") d = {} for i in txt: if i not in d: d[i] = {"len": len(i), "count": 1} else: d[i]["count"] += 1 l = [] for k, v in d.items(): if not l: for i in range(v["count"]): l.append(k) else: if len(l[0]) == len(k): for i in range(v["count"]): l.append(k) elif len(k) < len(l[0]): l = [] for i in range(v["count"]): l.append(k) return sorted(l)
9d66776ce5c84e1586b21cf3aaba923da868a2d4
daniel-reich/ubiquitous-fiesta
/H9gjahbSRbbGEpYta_3.py
294
3.796875
4
def multiply(n1, n2): positive = True if n1 < 0: n1 = -n1 positive = not positive if n2 < 0: n2 = -n2 positive = not positive n1, n2 = (n1, n2) if n1 >= n2 else (n2, n1) res = sum(n1 for _ in range(n2)) return res if positive else -res
3bc9ba2a984edf44bb70f8c91e5bea847a60669b
daniel-reich/ubiquitous-fiesta
/Fm7ap2w3exqunF9aJ_12.py
147
3.53125
4
import re ​ def count_lone_ones(n): return 0 if "1" not in str(n) else sum(1 if len(one) == 1 else 0 for one in re.findall(r"1+", str(n)))
ff38d23419024272358c274fef2496f9338cdb22
daniel-reich/ubiquitous-fiesta
/YN33GEpLQqa5imcFx_11.py
234
3.71875
4
import math ​ def pascals_triangle(row): n = row row_elements = '1' for k in range(1,row): row_elements += ' ' + str(int(math.factorial(n)/(math.factorial(k)*math.factorial(n-k)))) return row_elements+' 1'
c99a56c5ccd4558a910f2b5e12adf1aab97754a1
daniel-reich/ubiquitous-fiesta
/GPodAAMFqz9sLWmAy_19.py
201
3.546875
4
def one_odd_one_even(n): nums = list(map(int, str(n))) counter = [0,0] for n in nums: if n % 2 == 0: counter[0] = 1 elif n % 2 != 0: counter[1]= 1 return counter == [1,1]
bb36ed1fee716f1360264c082a41a4bd93e9246b
daniel-reich/ubiquitous-fiesta
/bKfxE7SWnRKTpyZQT_12.py
114
3.75
4
def replace_vowel(word): x = "aeiou" return ''.join([i if i not in x else str(x.index(i)+1) for i in word])
7954b00625ba96fab03f0b754b4f667130c5ca83
daniel-reich/ubiquitous-fiesta
/ub2KJNfsgjBMFJeqd_3.py
2,963
3.578125
4
import random ​ class Game: def __init__(self, r = 14, c = 18, m = 40): def init_board(r, c, m): bb = [] idx_mine = random.sample(range(r*c), m) for i in range(r): bb.append([]) for j in range(c): bb[i].append(Cell(i, j, (i*c)+j in idx_mine)) def update_neighbor(board, cell): n, r, c = cell.neighbors, cell.row, cell.col if not r and not c: for row in board[r:r+2]: for col in row[c:c+2]: if col.row == cell.row and col.col == cell.col: continue n += col.mine return n if not r and c: for row in board[r:r+2]: for col in row[c-1:c+2]: if col.row == cell.row and col.col == cell.col: continue n += col.mine return n if r and not c: for row in board[r-1:r+2]: for col in row[c:c+2]: if col.row == cell.row and col.col == cell.col: continue n += col.mine return n if r and c: for row in board[r-1:r+2]: for col in row[c-1:c+2]: if col.row == cell.row and col.col == cell.col: continue n += col.mine return n ​ def display(cell): if cell.mine: return 9 if cell.neighbors: return cell.neighbors if cell.open: return cell.neighbors if cell.flag: return 'F' return 0 for row in bb: for cell in row: cell.neighbors = update_neighbor(bb, cell) cell.display = display(cell) return bb self.rows = r self.cols = c self.mines = m self.bb = init_board(self.rows, self.cols, self.mines) self.board = self.bb def show_board(self): rows = [] for i, row in enumerate(self.board): rows.append([]) for j, col in enumerate(row): rows[i].append(col.display) for line in rows: print(line) ​ ​ class Cell(): def __init__(self, r, c, m): self.row = r self.col = c self.mine = m self.flag = False self.open = False self.neighbors = 0 self.display = 0
c7ffced0c1e9b0e09f1636e81db48b5bff8ee4e1
daniel-reich/ubiquitous-fiesta
/8rXfBzRZbgZP7mzyR_12.py
60
3.609375
4
def is_last_character_n(word): return (word[-1] == 'n')
c5a1540bd4430cf007d9b85ddb0256a4d919c7ae
daniel-reich/ubiquitous-fiesta
/82AvsFFQprj43XCDS_19.py
466
3.609375
4
from collections import defaultdict def no_strangers(words): counts, acquaintances, friends = defaultdict(int), [], [] words = words.replace('"','').replace('.','').replace(',','') for word in words.lower().split(): counts[word] += 1 if counts[word] == 3: acquaintances.append(word) elif counts[word] == 5: friends.append(acquaintances.pop(acquaintances.index(word))) return [acquaintances, friends]
4f6d91e5a8d412742a4c98e266041a9f61ba3746
daniel-reich/ubiquitous-fiesta
/PxxZprxCjDrzaTcLQ_7.py
206
3.578125
4
def vowel_links(txt): a = txt.split() vowels = "aeiou" for i in range (len(a)-1): if a[i][-1] in vowels and a[i+1][0] in vowels : return True # else: not need to use else return False
8b6ff01a34a64b24636448f87ff15d79b702a62e
daniel-reich/ubiquitous-fiesta
/ZT2mRQeYigSW2mojW_1.py
377
3.765625
4
import re ​ def syllable_count(s): syllables = 0 for i in re.findall("[a-z']+", s, re.I): groups = len(re.findall('[aeiouy]+', i, re.I)) syllables += max(1, groups - 1 if i.endswith(('e', 'es', "e's", 'ed')) and not i.endswith('le') else groups) return syllables ​ def haiku(s): return list(map(syllable_count, s.split('/'))) == [5, 7, 5]
6d860a7408f67888eed40b8cefa29344109f2cf5
daniel-reich/ubiquitous-fiesta
/BYDZmaM6e4TQrgneb_15.py
166
3.59375
4
def fib_fast(num): last = 1 lastlast = 0 out = 0 ​ for i in range(num-1): out = lastlast + last lastlast = last last = out return out
c9ae407dbcf646788b6268a965ef69e081bc6d65
daniel-reich/ubiquitous-fiesta
/4kwft4k6zebmM2BDX_0.py
306
3.5
4
def chi_squared_test(data): a, b = data['E'] c, d = data['T'] chi = round(((a*d - b*c)**2 * (a+b+c+d)) / ((a+b)*(c+d)*(b+d)*(a+c)), 1) if chi <= 3.841: return [chi, 'Edabitin is ininfluent'] return [chi, 'Edabitin effectiveness = {}%'.format(99 if chi > 6.635 else 95)]
100c36935aa96f84c30c4c0aae25b44299bf554d
daniel-reich/ubiquitous-fiesta
/jQGT8CNFcMXr55jeb_24.py
138
3.8125
4
def numbers_sum(lst): sum = 0 for thing in lst: if type(thing) == int: sum += thing else: continue return sum
0b26e0919a83b550e4f29469729df912d4063a15
daniel-reich/ubiquitous-fiesta
/b4fsyhyiRptsBzhcm_22.py
191
3.8125
4
def sum_even_nums_in_range(start, stop): x = 0 for i in range(start, stop + 1): if i % 2 == 0: x += i return x ​ ​ print(sum_even_nums_in_range(10, 20))
f95bad48aaafe891a1c6f2fd99c399ea73956118
daniel-reich/ubiquitous-fiesta
/qCsWceKoQ8tp2FMkr_20.py
89
3.703125
4
def is_triangle(a, b, c): return(True if (a+b>c) and (a+c>b) and (b+c>a) else False)
b84c78a6c52921476ef6274e2b07d331f6ecf76a
daniel-reich/ubiquitous-fiesta
/zRm6YDfQHoesdc3rb_9.py
152
3.828125
4
def rectangles(step): if step == 1: return 1 else: counter = 0 for i in range(1,step+1): counter += i**3 ​ return counter
c05a3b3a31276bf003deb86f3b350e261ac5da77
daniel-reich/ubiquitous-fiesta
/rbeuWab36FAiLj65m_0.py
255
3.71875
4
def grouping(words): words.sort(key=str.lower) groups = {} for w in words: cap = sum(map(str.isupper, w)) if cap in groups: groups[cap].append(w) else: groups[cap] = [w] return groups
9cb1d0c7f3437a856bff1d0adf3bbe1c7d58b7ff
daniel-reich/ubiquitous-fiesta
/KBmKcorkjbuXds6Jo_14.py
571
3.53125
4
def chocolates_parcel(n_small, n_big, order): ​ if (2 * n_small) + (5 * n_big) < order: return -1 if (2 * n_small) + (5 * n_big) == order: return n_small else: possibilites = [] for i in range(1, n_big + 1): if (order - (5 * i)) % 2 == 0: possibilites.append(i * 5) for i in possibilites: if i > order: possibilites.remove(i) if len(possibilites) > 0: return (order - max(possibilites)) / 2 else: for x in range(1, n_small + 1): if x * 2 == order: return x return -1
8b0dfc660c38dcfcf657e68aba5c72ef93ea5a06
daniel-reich/ubiquitous-fiesta
/KcnQtNoX5uC6PzpEF_13.py
142
3.59375
4
def check_sum(lst, n): for num in lst[:-1]: for next_num in lst[1:]: if num + next_num == n: return True return False
19181a102815485fc556ea61a01cfb87b17cd3e2
daniel-reich/ubiquitous-fiesta
/CvChvza6kwweMjNRr_21.py
218
3.5625
4
def split_code(item): s = list(item) letters = [] digits = [] for i in s: if i.isdigit(): digits.append(i) else: letters.append(i) return [''.join(letters), int(''.join(digits))]
9b1d631c52d78c9a5ac2d152af53b10044ab3333
daniel-reich/ubiquitous-fiesta
/tnKZCAkdnZpiuDiWA_22.py
154
3.890625
4
def flip_end_chars(txt): return "Incompatible." if len(txt)<2 or type(txt)!=str else "Two's a pair." if txt[0]==txt[-1] else txt[-1]+txt[1:-1]+txt[0]
bdb3dd5ba40c88027494d6503e5bf97884a7ec8d
daniel-reich/ubiquitous-fiesta
/QEL3QAY9ZhSkZcEih_16.py
269
4.0625
4
## Use Bitwise Operator (% modulo operator disallowed.) def is_odd(n): if int(n)%2==1: return 'Yes' else: return "No" ​ ## Use Regular Expression (% modulo operator disallowed.) def is_even(n): if int(n)%2==0: return 'Yes' else: return 'No'
427f8e70c154fd4ee5600c9ce0c6a030d76b8ff3
daniel-reich/ubiquitous-fiesta
/ix39oLQv3Zfppfvkg_14.py
189
3.546875
4
def multiply_matrix(m1, m2): if len(m1[0])!=len(m2): return "ERROR" return [[sum([m1[k][i]*m2[i][j] for i in range(len(m1[j]))]) for j in range(len(m1))] for k in range(len(m1))]
e99b21cd80b6ff0a6c9448bd68d9e08601e67529
daniel-reich/ubiquitous-fiesta
/aMTXfakahQ45oZbJP_0.py
202
3.515625
4
def complete_bracelet(lst): possible = [[tuple(lst[i:i+j]) for i in range(0,len(lst),j)] for j in range(2,(len(lst)//2)+1) if len(lst)%j == 0] return any(len(set(item)) == 1 for item in possible)
e7d619df383c28916f8a5d864cf62d5a2d5694dd
daniel-reich/ubiquitous-fiesta
/xCFHFha5sBmzsNARH_3.py
81
3.765625
4
def reverse(txt): if len(txt)<1:return '' return txt[-1]+reverse(txt[:-1])
1fbbce55d3a1bb0758c217bf1bac4c85b1616f1e
daniel-reich/ubiquitous-fiesta
/HSKvp4qYA2AhDWxn6_8.py
303
3.609375
4
def total_points(guesses, word): def score_guess(guess): for key,val in ({c:guess.count(c) for c in guess}).items(): if word.count(key) < val: return 0 return 1 if len(guess) == 3 else 2 if len(guess) == 4 else 3 if len(guess) == 5 else 54 return sum(map(score_guess, guesses))
18da6f240a2e8eb7f55637f198a40b5253aab921
daniel-reich/ubiquitous-fiesta
/QHuaoQuAJfWn2W9oX_12.py
1,201
3.671875
4
def check_board(col, row): col = ord(col) - 97 row = 8 - row ​ board = [ [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], ] # above for r in range(row - 1, -1, -1): board[r][col] = 1 # beneath for r in range(row + 1, 8): board[r][col] = 1 # right for c in range(col+1, 8): board[row][c] = 1 # left for c in range(col-1, -1, -1): board[row][c] = 1 ​ # above-right inc = 1 while col + inc < 8 and row - inc > -1: board[row-inc][col+inc] = 1 inc += 1 # above-left inc = 1 while col - inc > -1 and row - inc > -1: board[row - inc][col - inc] = 1 inc += 1 # beneath-right inc = 1 while col + inc < 8 and row + inc < 8: board[row + inc][col + inc] = 1 inc += 1 # beneath-left inc = 1 while col - inc > -1 and row + inc < 8: board[row + inc][col - inc] = 1 inc += 1 ​ return board
1cfa49f6d9656755d354678a218219a7f83b3b78
daniel-reich/ubiquitous-fiesta
/kSHpZ3KguSDSb5cwx_15.py
451
3.546875
4
moves = ["Shimmy", "Shake", "Pirouette", "Slide", "Box Step", "Headspin", "Dosado", "Pop", "Lock", "Arabesque"] ​ def dance_convert(pin): dance = [] for i in range(len(pin)): if pin[i].isdigit() and len(pin) == 4: if (i + int(pin[i])) < len(moves): dance.append(moves[i + int(pin[i])]) else: dance.append(moves[(i + int(pin[i])) - len(moves)]) else: return "Invalid input." break return dance
955e89fa2af02d7d2240d3f9be3d9dcfbcbbe5d1
daniel-reich/ubiquitous-fiesta
/temD7SmTyhdmME75i_23.py
244
3.828125
4
def to_boolean_list(word): alphabet = "abcdefghijklmnopqrstuvwxyz" output = [] for letter in word: if (alphabet.index(letter) + 1) % 2 != 0: output.append(True) else: output.append(False) return output
07ccd8719c34f703eb06a0d6497162c741acf903
daniel-reich/ubiquitous-fiesta
/jzCGNwLpmrHQKmtyJ_11.py
187
3.890625
4
def parity_analysis(num): temp=num sum=0 while(temp>0): sum+=temp%10 temp=temp//10 if (sum%2==0 and num%2==0) or (sum%2!=0 and num%2!=0): return True return False
fd24faccbd31eb246e365dbb2434f34ee827e054
daniel-reich/ubiquitous-fiesta
/4Y5Zk5f9LckvWjFf3_13.py
168
3.640625
4
def special_reverse(s, c): aux = list(s.split(" ")) for n in range(len(aux)): if(aux[n].startswith(c)): aux[n] = aux[n][::-1] return " ".join(aux)
9feed4af11eee414370cff1aa42f4a325c2a4671
daniel-reich/ubiquitous-fiesta
/hPCtfpyXDDawsz6xw_15.py
179
3.671875
4
def verbify(txt): a = txt.split() if a[0][-2:] == "ed": return " ".join(a) return a[0] + "d" + " " + a[-1] if a[0][-1] == "e" else a[0] + "ed" + " " + a[-1]
d055b099b9eaeed41da40b1559911b45fb89e1c7
daniel-reich/ubiquitous-fiesta
/SChr3sBY5ZKwHBHLH_12.py
142
3.890625
4
def sort_it(lst): z = list(zip([x[0] if type(x) == list else x for x in lst], lst)) print(z) r = sorted(z) return [x[1] for x in r]
126c392112188599f771aba4fb0126d7de5eedef
daniel-reich/ubiquitous-fiesta
/kjph2fGDWmLKY2n2J_7.py
733
3.640625
4
def valid_color(color): alpha = False percentage = False color = color.split('(') rg = color[0] if ' ' in rg: return False value = (color[1])[:-1].split(',') value = list(filter(lambda x: x != '', value)) if rg == 'rgba': alpha = True if rg == 'rgb' and len(value) != 3 or rg == 'rgba' and len(value) != 4: return False for k,i in enumerate(value): if '%' in i: i = i.replace('%', '') percentage = True try: ans = int(i) except: ans = float(i) if (percentage and (ans < 0 or ans > 100)) or (not percentage and (ans < 0 or ans > 255)) or (alpha and k == 3 and (ans < 0 or ans > 1)): return False return True
b8e1cb0e5b8ae77aab9bd28b26c0dcddf2a74355
daniel-reich/ubiquitous-fiesta
/bGRYmEZvzWFK2sbek_20.py
136
3.890625
4
import string def get_missing_letters(s): abc = string.ascii_lowercase return ''.join(sorted([x for x in abc if x not in s]))
e50d8186ecba5cc55b19903b9f1bc37db796b2a6
daniel-reich/ubiquitous-fiesta
/gQgFJiNy8ZDCqaZb4_9.py
523
3.609375
4
def overlap(s1, s2): smaller = min([len(s1),len(s2)]) if s1 == s2: return s1 if s1 in s2: return s2 for i in range(smaller): backthrough = smaller - i - 1 revthrough = (-1 * backthrough) print(backthrough) print(revthrough) print(s1[revthrough:]) print(s2[0:backthrough]) print('-----') if s1[revthrough:] == s2[0:backthrough]: begin = s1[0:revthrough] end = s2[backthrough:] overlap = s1[revthrough:] return begin + overlap + end return s1+s2
4205436ca0832d8762f69d9131773480f05d8214
daniel-reich/ubiquitous-fiesta
/6rztMMwkt6ijzqcF6_3.py
207
3.515625
4
def is_repeated(strn): lg = len(strn) for i in range(1,len(strn)//2+1): if lg%i: continue tmp = strn[:i] lt = len(tmp) if tmp*(lg//lt) == strn: return lg//lt return False
d09d2206f7c962e2a24617daa371f04876164059
daniel-reich/ubiquitous-fiesta
/X5K95S2nEmTrsJCPD_22.py
145
3.578125
4
emotion = {'smile': ':D', 'grin': ':)', 'sad': ':(', 'mad': ':P'} ​ def emotify(txt): return "Make me {}".format(emotion[txt.split()[-1]])
e2b37f0a3f9ccfc109081af363451aa040eab16d
daniel-reich/ubiquitous-fiesta
/p88k8yHRPTMPt4bBo_2.py
152
3.671875
4
def countVowels(string): vowels = ['a','e','i','o','u'] total = 0 for s in string: if s in vowels: total += 1 return total
2f8faedd7f4e29ec7e3a4e43f7fbaf6d5caf3682
daniel-reich/ubiquitous-fiesta
/ucsJxQNrkYnpzPaFj_18.py
154
3.515625
4
def char_appears(sentence, char): appearance = [] for word in sentence.lower().split(): appearance.append(word.count(char)) return appearance
7a769671de07d52128b9767c8829da223870a204
daniel-reich/ubiquitous-fiesta
/HvsBiHLGcsv2ex3gv_9.py
189
3.65625
4
import math def shortestDistance(txt): points = [int(item.strip()) for item in txt.split(',')] return round(math.sqrt((points[2] - points[0]) ** 2 + (points[3] - points[1]) ** 2), 2)
52ae582972d92e8b40cf98d342f05eb6bb512abc
daniel-reich/ubiquitous-fiesta
/XhyPkjEDQ3Mz5AFaH_5.py
647
3.609375
4
def is_match(s, p): def star_format(string, goal): if '*' not in string: return string else: ns = '' pi = None non_stars = [item for item in string if item != '*'] for item in string: if pi == None: pi = item ns += item elif item == '*': for n in range(len(goal) - len(non_stars)): ns += pi else: pi = item ns += item print(ns) return ns def dot_format(string): return '.' in string sf = star_format(p,s) df = dot_format(p) if df == True: return df print(sf) return sf == s
07538dc4215c899f4e2bd73ca7a890ff52740bda
daniel-reich/ubiquitous-fiesta
/KcD3bABvuryCfZAYv_0.py
147
3.671875
4
def most_frequent_char(lst): chars = ''.join(lst) return sorted(i for i in set(chars) if chars.count(i)==max(chars.count(j) for j in chars))
3e9be943b29edc979e16250aaf978ea1d20d10ee
daniel-reich/ubiquitous-fiesta
/BokhFunYBvsvHEjfx_23.py
114
3.53125
4
def seven_boom(lst): return "Boom!" if "7" in "".join([str(x) for x in lst]) else "there is no 7 in the list"
21b581f16f06ee680a9f00f9a3b47baf1f5a84e3
daniel-reich/ubiquitous-fiesta
/bd2fLqAxHfGTx86Qx_18.py
494
3.65625
4
def can_complete(initial, word): new_initial = [i for i in initial] new_word = [i for i in word] ​ space_left = len(new_word) - len(new_initial) for i in range(1,space_left+1): new_initial+=[" "] j = 0 for i in new_initial: if j >= len(new_word): break else: if i != new_word[j]: new_initial.insert(j, new_word[j]) j+=1 ​ join_back = "".join(new_initial).strip() ​ if join_back == word: return True else: return False
57a523f429410440171a74e73590ade50819117f
daniel-reich/ubiquitous-fiesta
/KExMohNcKkJYeTE2E_13.py
145
3.640625
4
def is_orthogonal(first, second): i = 0 list = [] for x in first: list.append(first[i]*second[i]) i += 1 return sum(list) == 0
f60a67ac06b4c081c1682feffbe3c1bb618a82ba
daniel-reich/ubiquitous-fiesta
/aBbZfPAM8pKRZjC6p_0.py
161
3.71875
4
def fruit_salad(fruits): salad = [] for fruit in fruits: mid = len(fruit) // 2 salad += [fruit[:mid], fruit[mid:]] return ''.join(sorted(salad))
bcece03900f0abd5e5ca2a690a56015234577109
daniel-reich/ubiquitous-fiesta
/Es985FEDzEQ2tkM75_23.py
184
3.890625
4
def caesar_cipher(text, key): alphabet = "abcdefghijklmnopqrstuvwxyz" return "".join([alphabet[((alphabet.find(char) + key) % 26)] if char.isalpha() else char for char in text])
cbfe4b9d269a74dc604370d99f3172d030f0100e
daniel-reich/ubiquitous-fiesta
/bHTb8p5nybCrjFPze_11.py
132
3.515625
4
def inclusive_list(start_num, end_num): return [_ for _ in range(start_num, end_num+1)] if start_num < end_num else [start_num]
63ccc715ac75c5955ce3a935cbfa33fe65295292
daniel-reich/ubiquitous-fiesta
/NybeH5L7wFPYeynCn_18.py
196
3.78125
4
def three_letter_collection(s): result = [] if len(s) <= 2: return result for i in range(len(s)): result.append(s[i:3+i]) if 3+i >= len(s): break return sorted(result)
df2fc0c14bfeedcd5af3510c2ea782c54ec86d82
daniel-reich/ubiquitous-fiesta
/FLgJEC8SK2AJYLC6y_10.py
247
4.03125
4
def possible_path(lst): is_possible = True dict_possible = {3: [4], 4: [3, 'H'], 'H': [2, 4], 1: [2], 2: [1,'H']} for i in range(len(lst) - 1): if lst[i + 1] not in dict_possible[lst[i]]: is_possible = False return is_possible
0f461e30346633e00a2a0e0cca9be2b984b22477
daniel-reich/ubiquitous-fiesta
/yfTyMb3SSumPQeuhm_2.py
245
3.90625
4
def fibonacci(n): return powerMN(n)[1] ​ def powerMN(n): if n == 1: return (1, 1) M, N = powerMN(n//2) M, N = (M**2 + 5*N**2) >> 1, M*N if n & 1: return ((M + 5*N)>>1, (M + N) >>1) else: return (M, N)
baeb1451064d9d820167cb32b493ffa27381e807
daniel-reich/ubiquitous-fiesta
/tgd8bCn8QtrqL4sdy_18.py
360
3.59375
4
def minesweeper(grid): rps = [[1,1],[1,0],[1,-1],[0,-1],[-1,-1],[-1,0],[-1,1],[0,1]] for x in range(3): for y in range(3): if grid[x][y] == "?": nh = 0 for rp in rps: if 0 <= rp[0]+x < 3 and 0 <= rp[1]+y < 3: if grid[rp[0] + x][rp[1] + y] == "#": nh += 1 grid[x][y] = str(nh) ​ return grid
6ea9d295cbd05f58b72c09d95f0d75e6a8b80008
daniel-reich/ubiquitous-fiesta
/arobBz954ZDxkDC9M_16.py
173
3.78125
4
def next_prime(num): primes = [2,3,5,7,11,13,17,19,23,29,31,37] if num in primes: return num for i in primes: if i > num: return i
a6c9ee562209cf587328f23d35ffd341e518d62c
daniel-reich/ubiquitous-fiesta
/e5XZ82bAk2rBo9EfS_6.py
602
3.796875
4
from datetime import timedelta, time, datetime, date ​ def bed_time(*times): return [go_to_sleep(*time) for time in times] def go_to_sleep(alarm_time, sleep_time): hours, minutes = sleep_time.split(":") hours, minutes = int(hours), int(minutes) delta_time = timedelta(hours=hours, minutes=minutes) hours, minutes = alarm_time.split(":") hours, minutes = int(hours), int(minutes) alarm_time = time(hour=hours, minute=minutes) sleep_time = (datetime.combine(date(3,3,3), alarm_time) - delta_time).time() return "{:02d}:{:02d}".format(sleep_time.hour, sleep_time.minute)
b1225e78df6ce217ebf8662b7cce5d67ceadecb4
daniel-reich/ubiquitous-fiesta
/79tuQhjqs8fT7zKCY_16.py
304
3.546875
4
def postfix(expr): temp_list = [] for c in expr.split(): if c not in ['+', '-', '*', '/']: temp_list.append(c) else: if len(temp_list) > 1: y = temp_list.pop() x = temp_list.pop() temp_list.append(eval("{}{}{}".format(x,c,y))) return int(temp_list[0])
e6a240c2ff0a804a7fe8f6b461e35443951f580a
daniel-reich/ubiquitous-fiesta
/FbQqXepHC4wxrWgYg_14.py
175
3.828125
4
def prime_divisors(num): divisors = set() i = 2 while num > 1: while num % i == 0: divisors.add(i) num = num // i i += 1 return sorted(divisors)
d56b9804a8400bc545e24cfa66f6c0cf3bf9ed97
daniel-reich/ubiquitous-fiesta
/c9i3mdjuwwzMF3Por_5.py
485
3.78125
4
def reverse(n): return int(str(n)[::-1]) ​ def up_down(n): s = '' for i in str(n): s += '6' if i == '9' else '9' if i == '6' else i return int(s) ​ def isprime(n): return all( n % i for i in range(2,n//2+1)) ​ def bemirp(n): if isprime(n): if n != reverse(n) and isprime(reverse(n)): if isprime(up_down(n)) and isprime(reverse(up_down(n))): return 'B' return 'E' return 'P' return 'C'