Skip to content

Commit

Permalink
fix: formatting with black thx @rafaels2
Browse files Browse the repository at this point in the history
  • Loading branch information
Aethelraed committed Jul 20, 2024
1 parent ae3c405 commit 683b994
Show file tree
Hide file tree
Showing 110 changed files with 9,986 additions and 2,272 deletions.
5 changes: 4 additions & 1 deletion acronym/acronym.py
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()
27 changes: 17 additions & 10 deletions all-your-base/all_your_base.py
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] :]
16 changes: 13 additions & 3 deletions allergies/allergies.py
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
6 changes: 5 additions & 1 deletion anagram/anagram.py
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()))
]
4 changes: 2 additions & 2 deletions armstrong-numbers/armstrong_numbers.py
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
18 changes: 12 additions & 6 deletions atbash-cipher/atbash_cipher.py
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
22 changes: 17 additions & 5 deletions binary-search/binary_search.py
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)
)
)
)
27 changes: 18 additions & 9 deletions black-jack/black_jack.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def value_of_card(card):
3. '2' - '10' = numerical value.
"""

if card in ["J","Q","K"]: return 10
if card in ["A"]: return 1
if card in ["J", "Q", "K"]:
return 10
if card in ["A"]:
return 1
return int(card)


Expand All @@ -32,9 +34,11 @@ def higher_card(card_one, card_two):
3. '2' - '10' = numerical value.
"""

if value_of_card(card_one)> value_of_card(card_two): return card_one
if value_of_card(card_one)< value_of_card(card_two): return card_two
return (card_one,card_two)
if value_of_card(card_one) > value_of_card(card_two):
return card_one
if value_of_card(card_one) < value_of_card(card_two):
return card_two
return (card_one, card_two)


def value_of_ace(card_one, card_two):
Expand All @@ -48,8 +52,10 @@ def value_of_ace(card_one, card_two):
3. '2' - '10' = numerical value.
"""


if value_of_card(card_one)+value_of_card(card_two)<11-(10*((card_one in "A" )| (card_two in "A"))): return 11
if value_of_card(card_one) + value_of_card(card_two) < 11 - (
10 * ((card_one in "A") | (card_two in "A"))
):
return 11
return 1


Expand All @@ -63,7 +69,10 @@ def is_blackjack(card_one, card_two):
2. 'A' (ace card) = 11 (if already in hand)
3. '2' - '10' = numerical value.
"""
if value_of_card(card_one)+value_of_card(card_two)==21-(10*((card_one in "A" )| (card_two in "A"))): return True
if value_of_card(card_one) + value_of_card(card_two) == 21 - (
10 * ((card_one in "A") | (card_two in "A"))
):
return True
return False


Expand All @@ -84,4 +93,4 @@ def can_double_down(card_one, card_two):
:return: bool - can the hand can be doubled down? (i.e. totals 9, 10 or 11 points).
"""

return (value_of_card(card_one)+value_of_card(card_two) ) in {9,10,11}
return (value_of_card(card_one) + value_of_card(card_two)) in {9, 10, 11}
Loading

0 comments on commit 683b994

Please sign in to comment.