From a5d5b08de04071517e3fe6b8d3c02b552afbb931 Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:23:16 +0200 Subject: [PATCH 1/9] fix assignment of a variable to itself --- ciphers/enigma_machine2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ciphers/enigma_machine2.py b/ciphers/enigma_machine2.py index 0fbe97284d38..fa184c748b93 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -124,7 +124,8 @@ def _plugboard(pbstring: str) -> dict: # a) is type string # b) has even length (so pairs can be made) if not isinstance(pbstring, str): - raise TypeError(f"Plugboard setting isn't type string ({type(pbstring)})") + raise TypeError( + f"Plugboard setting isn't type string ({type(pbstring)})") elif len(pbstring) % 2 != 0: raise Exception(f"Odd number of symbols ({len(pbstring)})") elif pbstring == "": @@ -218,7 +219,6 @@ def enigma( rotorpos1 -= 1 rotorpos2 -= 1 rotorpos3 -= 1 - plugboard = plugboard result = [] From d2c2bba17279ad7b0be46bd0470bb196b52ea29a Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:25:27 +0200 Subject: [PATCH 2/9] Fix unnecessary 'else' clause in loop --- other/triplet_sum.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/other/triplet_sum.py b/other/triplet_sum.py index 247e3bb1618d..25fed5d54579 100644 --- a/other/triplet_sum.py +++ b/other/triplet_sum.py @@ -61,8 +61,7 @@ def triplet_sum2(arr: List[int], target: int) -> Tuple[int, int, int]: left += 1 elif arr[i] + arr[left] + arr[right] > target: right -= 1 - else: - return (0, 0, 0) + return (0, 0, 0) def solution_times() -> Tuple[float, float]: From ad7977a342426253dbbeb8cd011ebc214f176a6b Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:35:34 +0200 Subject: [PATCH 3/9] formatting and redundant reasignment fix --- scheduling/shortest_job_first.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scheduling/shortest_job_first.py b/scheduling/shortest_job_first.py index 6a2fdeeecc5a..9ff01ba282f2 100644 --- a/scheduling/shortest_job_first.py +++ b/scheduling/shortest_job_first.py @@ -11,7 +11,6 @@ def calculate_waitingtime( arrival_time: List[int], burst_time: List[int], no_of_processes: int ) -> List[int]: - """ Calculate the waiting time of each processes Return: list of waiting times. @@ -112,7 +111,8 @@ def calculate_average_times( for i in range(no_of_processes): total_waiting_time = total_waiting_time + waiting_time[i] total_turn_around_time = total_turn_around_time + turn_around_time[i] - print("Average waiting time = %.5f" % (total_waiting_time / no_of_processes)) + print("Average waiting time = %.5f" % + (total_waiting_time / no_of_processes)) print("Average turn around time =", total_turn_around_time / no_of_processes) @@ -126,15 +126,20 @@ def calculate_average_times( for i in range(no_of_processes): print("Enter the arrival time and brust time for process:--" + str(i + 1)) arrival_time[i], burst_time[i] = map(int, input().split()) - waiting_time = calculate_waitingtime(arrival_time, burst_time, no_of_processes) + + waiting_time = calculate_waitingtime( + arrival_time, burst_time, no_of_processes) + bt = burst_time n = no_of_processes wt = waiting_time turn_around_time = calculate_turnaroundtime(bt, n, wt) + calculate_average_times(waiting_time, turn_around_time, no_of_processes) - processes = list(range(1, no_of_processes + 1)) + fcfs = pd.DataFrame( - list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)), + list(zip(processes, burst_time, arrival_time, + waiting_time, turn_around_time)), columns=[ "Process", "BurstTime", From a14bed8cb041f814654bcbde9b985701af55afe3 Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:42:50 +0200 Subject: [PATCH 4/9] mark unreachable code with a TODO comment --- graphs/directed_and_undirected_(weighted)_graph.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/graphs/directed_and_undirected_(weighted)_graph.py b/graphs/directed_and_undirected_(weighted)_graph.py index 61e196adfaac..e4fe97d29f04 100644 --- a/graphs/directed_and_undirected_(weighted)_graph.py +++ b/graphs/directed_and_undirected_(weighted)_graph.py @@ -226,7 +226,9 @@ def has_cycle(self): break else: return True - anticipating_nodes.add(stack[len_stack_minus_one]) + # TODO:The following code is unreachable. + anticipating_nodes.add( + stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: stack.append(node[1]) @@ -453,7 +455,10 @@ def has_cycle(self): break else: return True - anticipating_nodes.add(stack[len_stack_minus_one]) + # TODO: the following code is unreachable + # is this meant to be called in the else ? + anticipating_nodes.add( + stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: stack.append(node[1]) From 90d31e88cfe545519de22f22cbc951a8cdb08994 Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:45:37 +0200 Subject: [PATCH 5/9] fix variable defined multiple times --- maths/chudnovsky_algorithm.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/maths/chudnovsky_algorithm.py b/maths/chudnovsky_algorithm.py index fb188cd6a3d8..9adc2dfa89f8 100644 --- a/maths/chudnovsky_algorithm.py +++ b/maths/chudnovsky_algorithm.py @@ -44,15 +44,16 @@ def pi(precision: int) -> str: getcontext().prec = precision num_iterations = ceil(precision / 14) constant_term = 426880 * Decimal(10005).sqrt() - multinomial_term = 1 exponential_term = 1 linear_term = 13591409 partial_sum = Decimal(linear_term) for k in range(1, num_iterations): - multinomial_term = factorial(6 * k) // (factorial(3 * k) * factorial(k) ** 3) + multinomial_term = factorial( + 6 * k) // (factorial(3 * k) * factorial(k) ** 3) linear_term += 545140134 exponential_term *= -262537412640768000 - partial_sum += Decimal(multinomial_term * linear_term) / exponential_term + partial_sum += Decimal(multinomial_term * + linear_term) / exponential_term return str(constant_term / partial_sum)[:-1] From d6dd098b7ddc8cadb89f61d4d3f142d1a6327272 Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 08:49:06 +0200 Subject: [PATCH 6/9] fix static method without static decorator --- graphs/minimum_spanning_tree_boruvka.py | 1 + 1 file changed, 1 insertion(+) diff --git a/graphs/minimum_spanning_tree_boruvka.py b/graphs/minimum_spanning_tree_boruvka.py index f65aa7cef031..3b05f94b5140 100644 --- a/graphs/minimum_spanning_tree_boruvka.py +++ b/graphs/minimum_spanning_tree_boruvka.py @@ -146,6 +146,7 @@ def union(self, item1, item2): self.parent[root2] = root1 return root1 + @staticmethod def boruvka_mst(graph): """ Implementation of Boruvka's algorithm From 82243cd0dc5c83e6381dc1c36b94ba0e1423a10a Mon Sep 17 00:00:00 2001 From: Hasenn Date: Sun, 13 Sep 2020 09:02:54 +0200 Subject: [PATCH 7/9] revert unintended autoformatting Co-authored-by: Christian Clauss --- ciphers/enigma_machine2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ciphers/enigma_machine2.py b/ciphers/enigma_machine2.py index fa184c748b93..45386e43d181 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -125,7 +125,8 @@ def _plugboard(pbstring: str) -> dict: # b) has even length (so pairs can be made) if not isinstance(pbstring, str): raise TypeError( - f"Plugboard setting isn't type string ({type(pbstring)})") + f"Plugboard setting isn't type string ({type(pbstring)})" + ) elif len(pbstring) % 2 != 0: raise Exception(f"Odd number of symbols ({len(pbstring)})") elif pbstring == "": From dcebd72e9439365c39dea9d584b70967e8a4028d Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 09:05:34 +0200 Subject: [PATCH 8/9] revert autoformatting issue --- maths/chudnovsky_algorithm.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/maths/chudnovsky_algorithm.py b/maths/chudnovsky_algorithm.py index 9adc2dfa89f8..99c125033648 100644 --- a/maths/chudnovsky_algorithm.py +++ b/maths/chudnovsky_algorithm.py @@ -52,8 +52,7 @@ def pi(precision: int) -> str: 6 * k) // (factorial(3 * k) * factorial(k) ** 3) linear_term += 545140134 exponential_term *= -262537412640768000 - partial_sum += Decimal(multinomial_term * - linear_term) / exponential_term + partial_sum += Decimal(multinomial_term * linear_term) / exponential_term return str(constant_term / partial_sum)[:-1] From 7e359c78781167f597ff742817efabe460bf8ab0 Mon Sep 17 00:00:00 2001 From: eliott veyrier Date: Sun, 13 Sep 2020 09:08:46 +0200 Subject: [PATCH 9/9] applied black autoformatting --- ciphers/enigma_machine2.py | 4 +--- graphs/directed_and_undirected_(weighted)_graph.py | 6 ++---- maths/chudnovsky_algorithm.py | 3 +-- scheduling/shortest_job_first.py | 9 +++------ 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/ciphers/enigma_machine2.py b/ciphers/enigma_machine2.py index 45386e43d181..4344db0056fd 100644 --- a/ciphers/enigma_machine2.py +++ b/ciphers/enigma_machine2.py @@ -124,9 +124,7 @@ def _plugboard(pbstring: str) -> dict: # a) is type string # b) has even length (so pairs can be made) if not isinstance(pbstring, str): - raise TypeError( - f"Plugboard setting isn't type string ({type(pbstring)})" - ) + raise TypeError(f"Plugboard setting isn't type string ({type(pbstring)})") elif len(pbstring) % 2 != 0: raise Exception(f"Odd number of symbols ({len(pbstring)})") elif pbstring == "": diff --git a/graphs/directed_and_undirected_(weighted)_graph.py b/graphs/directed_and_undirected_(weighted)_graph.py index e4fe97d29f04..5cfa9e13edd9 100644 --- a/graphs/directed_and_undirected_(weighted)_graph.py +++ b/graphs/directed_and_undirected_(weighted)_graph.py @@ -227,8 +227,7 @@ def has_cycle(self): else: return True # TODO:The following code is unreachable. - anticipating_nodes.add( - stack[len_stack_minus_one]) + anticipating_nodes.add(stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: stack.append(node[1]) @@ -457,8 +456,7 @@ def has_cycle(self): return True # TODO: the following code is unreachable # is this meant to be called in the else ? - anticipating_nodes.add( - stack[len_stack_minus_one]) + anticipating_nodes.add(stack[len_stack_minus_one]) len_stack_minus_one -= 1 if visited.count(node[1]) < 1: stack.append(node[1]) diff --git a/maths/chudnovsky_algorithm.py b/maths/chudnovsky_algorithm.py index 99c125033648..aaee7462822e 100644 --- a/maths/chudnovsky_algorithm.py +++ b/maths/chudnovsky_algorithm.py @@ -48,8 +48,7 @@ def pi(precision: int) -> str: linear_term = 13591409 partial_sum = Decimal(linear_term) for k in range(1, num_iterations): - multinomial_term = factorial( - 6 * k) // (factorial(3 * k) * factorial(k) ** 3) + multinomial_term = factorial(6 * k) // (factorial(3 * k) * factorial(k) ** 3) linear_term += 545140134 exponential_term *= -262537412640768000 partial_sum += Decimal(multinomial_term * linear_term) / exponential_term diff --git a/scheduling/shortest_job_first.py b/scheduling/shortest_job_first.py index 9ff01ba282f2..ecb6e01fdfe6 100644 --- a/scheduling/shortest_job_first.py +++ b/scheduling/shortest_job_first.py @@ -111,8 +111,7 @@ def calculate_average_times( for i in range(no_of_processes): total_waiting_time = total_waiting_time + waiting_time[i] total_turn_around_time = total_turn_around_time + turn_around_time[i] - print("Average waiting time = %.5f" % - (total_waiting_time / no_of_processes)) + print("Average waiting time = %.5f" % (total_waiting_time / no_of_processes)) print("Average turn around time =", total_turn_around_time / no_of_processes) @@ -127,8 +126,7 @@ def calculate_average_times( print("Enter the arrival time and brust time for process:--" + str(i + 1)) arrival_time[i], burst_time[i] = map(int, input().split()) - waiting_time = calculate_waitingtime( - arrival_time, burst_time, no_of_processes) + waiting_time = calculate_waitingtime(arrival_time, burst_time, no_of_processes) bt = burst_time n = no_of_processes @@ -138,8 +136,7 @@ def calculate_average_times( calculate_average_times(waiting_time, turn_around_time, no_of_processes) fcfs = pd.DataFrame( - list(zip(processes, burst_time, arrival_time, - waiting_time, turn_around_time)), + list(zip(processes, burst_time, arrival_time, waiting_time, turn_around_time)), columns=[ "Process", "BurstTime",