Code formatting
This commit is contained in:
parent
419bc694b2
commit
a96cef4bfa
6 changed files with 42 additions and 32 deletions
|
@ -16,7 +16,7 @@ def run_and_time(f):
|
|||
st = time.time()
|
||||
x = f()
|
||||
et = time.time()
|
||||
return x, et-st
|
||||
return x, et - st
|
||||
|
||||
|
||||
def run_tests(test_cases):
|
||||
|
@ -36,7 +36,7 @@ def run_tests(test_cases):
|
|||
for i, tc in enumerate(tcs):
|
||||
readable_test_num = f"{n}.{i+1}"
|
||||
print(f"Running {readable_test_num}...", end="\r")
|
||||
|
||||
|
||||
expectedInt = tc["expected"]
|
||||
|
||||
result, t = run_and_time(lambda: f(str(tc["input"])))
|
||||
|
@ -46,12 +46,14 @@ def run_tests(test_cases):
|
|||
if result == expectedInt:
|
||||
output_string += "[green]pass[/green]"
|
||||
else:
|
||||
output_string += f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
|
||||
output_string += (
|
||||
f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
)
|
||||
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
|
||||
print(output_string + " "*12)
|
||||
|
||||
print(output_string + " " * 12)
|
||||
|
||||
rt(test_cases["one"], partOne, 1)
|
||||
rt(test_cases["two"], partTwo, 2)
|
||||
|
@ -98,14 +100,14 @@ if __name__ == "__main__":
|
|||
sys.exit()
|
||||
|
||||
print("Answers")
|
||||
|
||||
|
||||
print("Running part 1...", end="\r")
|
||||
output_string = "Part 1: "
|
||||
x, t = run_and_time(lambda: partOne(challenge_input))
|
||||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
||||
print("Running part 2...", end="\r")
|
||||
output_string = "Part 2: "
|
||||
|
@ -113,4 +115,4 @@ if __name__ == "__main__":
|
|||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from common import *
|
||||
import time
|
||||
|
||||
|
||||
def play_round(deck_one: List[int], deck_two: List[int]) -> None:
|
||||
|
||||
top_one = deck_one.pop(0)
|
||||
|
|
|
@ -2,7 +2,9 @@ from common import *
|
|||
import copy
|
||||
|
||||
|
||||
def play_round(deck_one: List[int], deck_two: List[int]) -> Tuple[int, Tuple[List[int], List[int]]]:
|
||||
def play_round(
|
||||
deck_one: List[int], deck_two: List[int]
|
||||
) -> Tuple[int, Tuple[List[int], List[int]]]:
|
||||
# returns winner number and decks in their new state
|
||||
|
||||
# print("new round")
|
||||
|
@ -41,7 +43,7 @@ def play_round(deck_one: List[int], deck_two: List[int]) -> Tuple[int, Tuple[Lis
|
|||
|
||||
# print(winner, "wins")
|
||||
|
||||
# do things based on the winner
|
||||
# do things based on the winner
|
||||
if winner == 1:
|
||||
deck_one.append(top_one)
|
||||
deck_one.append(top_two)
|
||||
|
@ -49,7 +51,7 @@ def play_round(deck_one: List[int], deck_two: List[int]) -> Tuple[int, Tuple[Lis
|
|||
deck_two.append(top_two)
|
||||
deck_two.append(top_one)
|
||||
else:
|
||||
raise Exception("SDFGKSHDFGKSHDFGAAAAAAAA!!!") # yes
|
||||
raise Exception("SDFGKSHDFGKSHDFGAAAAAAAA!!!") # yes
|
||||
|
||||
# print("finished this round")
|
||||
|
||||
|
@ -59,7 +61,9 @@ def play_round(deck_one: List[int], deck_two: List[int]) -> Tuple[int, Tuple[Lis
|
|||
def partTwo(instr: str) -> int:
|
||||
deck_one, deck_two = parse(instr)
|
||||
|
||||
winner, (deck_one, deck_two) = play_round(copy.deepcopy(deck_one), copy.deepcopy(deck_two))
|
||||
winner, (deck_one, deck_two) = play_round(
|
||||
copy.deepcopy(deck_one), copy.deepcopy(deck_two)
|
||||
)
|
||||
|
||||
if winner == 1:
|
||||
return calc_score(deck_one)
|
||||
|
|
|
@ -16,7 +16,7 @@ def run_and_time(f):
|
|||
st = time.time()
|
||||
x = f()
|
||||
et = time.time()
|
||||
return x, et-st
|
||||
return x, et - st
|
||||
|
||||
|
||||
def run_tests(test_cases):
|
||||
|
@ -36,7 +36,7 @@ def run_tests(test_cases):
|
|||
for i, tc in enumerate(tcs):
|
||||
readable_test_num = f"{n}.{i+1}"
|
||||
print(f"Running {readable_test_num}...", end="\r")
|
||||
|
||||
|
||||
expectedInt = tc["expected"]
|
||||
|
||||
result, t = run_and_time(lambda: f(str(tc["input"])))
|
||||
|
@ -46,12 +46,14 @@ def run_tests(test_cases):
|
|||
if result == expectedInt:
|
||||
output_string += "[green]pass[/green]"
|
||||
else:
|
||||
output_string += f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
|
||||
output_string += (
|
||||
f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
)
|
||||
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
|
||||
print(output_string + " "*12)
|
||||
|
||||
print(output_string + " " * 12)
|
||||
|
||||
rt(test_cases["one"], partOne, 1)
|
||||
rt(test_cases["two"], partTwo, 2)
|
||||
|
@ -98,14 +100,14 @@ if __name__ == "__main__":
|
|||
sys.exit()
|
||||
|
||||
print("Answers")
|
||||
|
||||
|
||||
print("Running part 1...", end="\r")
|
||||
output_string = "Part 1: "
|
||||
x, t = run_and_time(lambda: partOne(challenge_input))
|
||||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
||||
print("Running part 2...", end="\r")
|
||||
output_string = "Part 2: "
|
||||
|
@ -113,4 +115,4 @@ if __name__ == "__main__":
|
|||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
|
|
@ -60,7 +60,6 @@ def partOne(instr: str) -> int:
|
|||
|
||||
print()
|
||||
|
||||
|
||||
# rotate until 1 is the first value
|
||||
while cups[0] != 1:
|
||||
t = cups.pop(0)
|
||||
|
|
|
@ -16,7 +16,7 @@ def run_and_time(f):
|
|||
st = time.time()
|
||||
x = f()
|
||||
et = time.time()
|
||||
return x, et-st
|
||||
return x, et - st
|
||||
|
||||
|
||||
def run_tests(test_cases):
|
||||
|
@ -36,7 +36,7 @@ def run_tests(test_cases):
|
|||
for i, tc in enumerate(tcs):
|
||||
readable_test_num = f"{n}.{i+1}"
|
||||
print(f"Running {readable_test_num}...", end="\r")
|
||||
|
||||
|
||||
expectedInt = tc["expected"]
|
||||
|
||||
result, t = run_and_time(lambda: f(str(tc["input"])))
|
||||
|
@ -46,12 +46,14 @@ def run_tests(test_cases):
|
|||
if result == expectedInt:
|
||||
output_string += "[green]pass[/green]"
|
||||
else:
|
||||
output_string += f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
|
||||
output_string += (
|
||||
f"[red]fail[/red] (got {result}, expected {expectedInt})"
|
||||
)
|
||||
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
|
||||
print(output_string + " "*12)
|
||||
|
||||
print(output_string + " " * 12)
|
||||
|
||||
rt(test_cases["one"], partOne, 1)
|
||||
rt(test_cases["two"], partTwo, 2)
|
||||
|
@ -98,14 +100,14 @@ if __name__ == "__main__":
|
|||
sys.exit()
|
||||
|
||||
print("Answers")
|
||||
|
||||
|
||||
print("Running part 1...", end="\r")
|
||||
output_string = "Part 1: "
|
||||
x, t = run_and_time(lambda: partOne(challenge_input))
|
||||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
||||
print("Running part 2...", end="\r")
|
||||
output_string = "Part 2: "
|
||||
|
@ -113,4 +115,4 @@ if __name__ == "__main__":
|
|||
output_string += str(x)
|
||||
if t > 15 or force_time:
|
||||
output_string += f" in {t} seconds"
|
||||
print(output_string + " "*12)
|
||||
print(output_string + " " * 12)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue