From 514b80b44b98df34457e564989598811d986c567 Mon Sep 17 00:00:00 2001 From: handcraftsman Date: Fri, 31 May 2019 18:23:52 -0500 Subject: [PATCH 1/5] fix tabs vs spaces in merged code segment reported by Piotr.Lewczuk@uk-erlangen.de --- ch09/knapsackTests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch09/knapsackTests.py b/ch09/knapsackTests.py index b589088..a1c1e53 100644 --- a/ch09/knapsackTests.py +++ b/ch09/knapsackTests.py @@ -255,8 +255,8 @@ def __init__(self, totalWeight, totalVolume, totalValue): def __gt__(self, other): if self.TotalValue != other.TotalValue: return self.TotalValue > other.TotalValue - if self.TotalWeight != other.TotalWeight: - return self.TotalWeight < other.TotalWeight + if self.TotalWeight != other.TotalWeight: + return self.TotalWeight < other.TotalWeight return self.TotalValue < other.TotalValue def __str__(self): From 322eda59dc9f0acf2e145abaf82fef7dbed7d556 Mon Sep 17 00:00:00 2001 From: handcraftsman Date: Fri, 31 May 2019 19:13:47 -0500 Subject: [PATCH 2/5] change knapsack Fitness to compare Volume last --- ch09/knapsackTests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ch09/knapsackTests.py b/ch09/knapsackTests.py index a1c1e53..2f7ac5f 100644 --- a/ch09/knapsackTests.py +++ b/ch09/knapsackTests.py @@ -254,10 +254,10 @@ def __init__(self, totalWeight, totalVolume, totalValue): def __gt__(self, other): if self.TotalValue != other.TotalValue: - return self.TotalValue > other.TotalValue + return self.TotalValue > other.TotalValue if self.TotalWeight != other.TotalWeight: return self.TotalWeight < other.TotalWeight - return self.TotalValue < other.TotalValue + return self.TotalVolume < other.TotalVolume def __str__(self): return "wt: {:0.2f} vol: {:0.2f} value: {}".format( From 2a71f2882b0ecad1ba692d3bf9bc74ce9d02b37d Mon Sep 17 00:00:00 2001 From: handcraftsman Date: Fri, 21 Jun 2019 08:58:22 -0500 Subject: [PATCH 3/5] prevent FutureWarning about || inside a [..] regex --- ch17/regexTests.py | 2 ++ es/ch17/regex.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/ch17/regexTests.py b/ch17/regexTests.py index 39d654d..63bc94b 100644 --- a/ch17/regexTests.py +++ b/ch17/regexTests.py @@ -96,6 +96,8 @@ def repair_in_character_set(token, result, finals): return repair_ignore_repeat_metas_following_repeat_or_start_metas elif token == '[': pass + elif token == '|' and result[-1] == '|': + pass # suppresses FutureWarning about || else: result.append(token) return repair_in_character_set diff --git a/es/ch17/regex.py b/es/ch17/regex.py index f29d61f..8e5cd61 100644 --- a/es/ch17/regex.py +++ b/es/ch17/regex.py @@ -95,6 +95,8 @@ def reparar_in_character_set(símbolo, resultado, finales): return manejar_metas_de_repetición_que_siguen_metas_de_repetición_o_inicio elif símbolo == '[': pass + elif símbolo == '|' and resultado[-1] == '|': + pass # suprimir FutureWarning sobre || else: resultado.append(símbolo) return reparar_in_character_set From 565e405ad0df8d3c360cfc9c335dbacfcc3041c0 Mon Sep 17 00:00:00 2001 From: ErfanThinker Date: Sat, 4 Jul 2020 11:32:32 +0430 Subject: [PATCH 4/5] Removed redundant condition --- ch16/circuitTests.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ch16/circuitTests.py b/ch16/circuitTests.py index 5e139b6..1f53295 100644 --- a/ch16/circuitTests.py +++ b/ch16/circuitTests.py @@ -53,8 +53,7 @@ def create_gene(index, gates, sources): if gateType[1].input_count() > 0: indexA = random.randint(0, index) if gateType[1].input_count() > 1: - indexB = random.randint(0, index) \ - if index > 1 and index >= len(sources) else 0 + indexB = random.randint(0, index) if indexB == indexA: indexB = random.randint(0, index) return Node(gateType[0], indexA, indexB) From 2359440659559fae56b156fe30320b5f5f9a77ee Mon Sep 17 00:00:00 2001 From: handcraftsman Date: Tue, 7 Jul 2020 07:36:56 -0500 Subject: [PATCH 5/5] make ErfanThinker's change in the Spanish version --- es/ch16/pruebas.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/es/ch16/pruebas.py b/es/ch16/pruebas.py index d11f6a8..03a1a8d 100644 --- a/es/ch16/pruebas.py +++ b/es/ch16/pruebas.py @@ -53,8 +53,7 @@ def crear_gen(índice, puertas, fuentes): if tipoDePuerta[1].recuento_de_entradas() > 0: índiceA = random.randint(0, índice) if tipoDePuerta[1].recuento_de_entradas() > 1: - índiceB = random.randint(0, índice) \ - if índice > 1 and índice >= len(fuentes) else 0 + índiceB = random.randint(0, índice) if índiceB == índiceA: índiceB = random.randint(0, índice) return Nodo(tipoDePuerta[0], índiceA, índiceB)