-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: formatting with black thx @rafaels2
- Loading branch information
1 parent
ae3c405
commit 683b994
Showing
110 changed files
with
9,986 additions
and
2,272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
def abbreviate(words): | ||
return "".join(i[0] for i in words.replace("-"," ").replace("_","").replace(" "," ").split(" ")).upper() | ||
return "".join( | ||
i[0] | ||
for i in words.replace("-", " ").replace("_", "").replace(" ", " ").split(" ") | ||
).upper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
import math | ||
|
||
|
||
def rebase(input_base, digits, output_base): | ||
if input_base< 2:raise ValueError("input base must be >= 2") | ||
if len(digits) and (min (digits)<0 or max(digits)>= input_base): raise ValueError("all digits must satisfy 0 <= d < input base") | ||
if output_base < 2: raise ValueError("output base must be >= 2") | ||
if not sum(digits): return [0] | ||
help =0 | ||
if input_base < 2: | ||
raise ValueError("input base must be >= 2") | ||
if len(digits) and (min(digits) < 0 or max(digits) >= input_base): | ||
raise ValueError("all digits must satisfy 0 <= d < input base") | ||
if output_base < 2: | ||
raise ValueError("output base must be >= 2") | ||
if not sum(digits): | ||
return [0] | ||
help = 0 | ||
out = [] | ||
for index,dig in enumerate(digits): help = help + dig * input_base**(len (digits)-index-1) | ||
for i in range (math.ceil(math.log(help,output_base)),-1,-1): | ||
out = out+[help//(output_base**i)] | ||
help = help% (output_base**i) | ||
return out[not out[0]:] | ||
for index, dig in enumerate(digits): | ||
help = help + dig * input_base ** (len(digits) - index - 1) | ||
for i in range(math.ceil(math.log(help, output_base)), -1, -1): | ||
out = out + [help // (output_base**i)] | ||
help = help % (output_base**i) | ||
return out[not out[0] :] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
class Allergies: | ||
|
||
def __init__(self, score): | ||
self.lst,candidates= [],{"cats":128,"pollen":64,"chocolate":32,"tomatoes":16,"strawberries":8,"shellfish":4,"peanuts":2,"eggs":1} | ||
self.lst, candidates = [], { | ||
"cats": 128, | ||
"pollen": 64, | ||
"chocolate": 32, | ||
"tomatoes": 16, | ||
"strawberries": 8, | ||
"shellfish": 4, | ||
"peanuts": 2, | ||
"eggs": 1, | ||
} | ||
for i in range(len(candidates)): | ||
if score%256 >= list(candidates.values())[i]: | ||
if score % 256 >= list(candidates.values())[i]: | ||
score -= list(candidates.values())[i] | ||
self.lst.append(list(candidates.keys())[i]) | ||
|
||
def allergic_to(self, item): return item in self.lst | ||
def allergic_to(self, item): | ||
return item in self.lst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
def find_anagrams(word, candidates): | ||
return [c for c in candidates if (sorted(c.lower()) == sorted(word.lower()) and (word.lower() != c.lower()))] | ||
return [ | ||
c | ||
for c in candidates | ||
if (sorted(c.lower()) == sorted(word.lower()) and (word.lower() != c.lower())) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
def is_armstrong_number(number): | ||
h_sum = 0 | ||
for i in str(number): | ||
h_sum = h_sum + int(i)**len(str(number)) | ||
return (number == h_sum) | ||
h_sum = h_sum + int(i) ** len(str(number)) | ||
return number == h_sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
dt,td= list(tuple("abcdefghijklmnopqrstuvwxyz1234567890")),list(tuple("zyxwvutsrqponmlkjihgfedcba1234567890")) | ||
dt, td = list(tuple("abcdefghijklmnopqrstuvwxyz1234567890")), list( | ||
tuple("zyxwvutsrqponmlkjihgfedcba1234567890") | ||
) | ||
|
||
|
||
def encode(plain_text): | ||
out,i = "",0 | ||
out, i = "", 0 | ||
for c in plain_text: | ||
if c in" .!?,": continue | ||
out,i=out+td[dt.index(c.lower())],i+1 | ||
if i %5==0: out,i=out+" ", 0 | ||
if c in " .!?,": | ||
continue | ||
out, i = out + td[dt.index(c.lower())], i + 1 | ||
if i % 5 == 0: | ||
out, i = out + " ", 0 | ||
return out.strip(" ") | ||
|
||
|
||
def decode(cipher): | ||
out = "" | ||
for c in "".join(cipher.split(" ")): | ||
out=out+dt[td.index(c.lower())] | ||
out = out + dt[td.index(c.lower())] | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,17 @@ | ||
def find(search_list, value, index = 0): | ||
sll,pv = len(search_list), len(search_list)//2 -1 | ||
if sll==0 or value < search_list[0] or value > search_list[sll-1]: raise ValueError("value not in array") | ||
return index if value == search_list[0] else index +sll-1 if value == search_list[sll-1] else find(search_list[:pv], value,pv) if value < search_list[pv] else find(search_list[pv:],value,index+pv) | ||
|
||
def find(search_list, value, index=0): | ||
sll, pv = len(search_list), len(search_list) // 2 - 1 | ||
if sll == 0 or value < search_list[0] or value > search_list[sll - 1]: | ||
raise ValueError("value not in array") | ||
return ( | ||
index | ||
if value == search_list[0] | ||
else ( | ||
index + sll - 1 | ||
if value == search_list[sll - 1] | ||
else ( | ||
find(search_list[:pv], value, pv) | ||
if value < search_list[pv] | ||
else find(search_list[pv:], value, index + pv) | ||
) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.