From 606a2d2924eb656cfe9cf838f270bef2e17d1e30 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Fri, 13 Apr 2018 18:56:36 +0000 Subject: [PATCH] Simplified some logic in Python and Rust code. --- python/qrcodegen.py | 9 +++------ rust/src/lib.rs | 10 ++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 9a5b32c..cc5cdbf 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -498,12 +498,9 @@ class QrCode(object): step = (ver * 4 + numalign * 2 + 1) // (2 * numalign - 2) * 2 else: # C-C-C-Combo breaker! step = 26 - result = [6] - pos = ver * 4 + 10 - for _ in range(numalign - 1): - result.insert(1, pos) - pos -= step - return result + start = ver * 4 + 10 + result = [(start - i * step) for i in range(numalign - 1)] + [6] + return list(reversed(result)) @staticmethod diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 3f17db4..fead074 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -628,12 +628,10 @@ impl QrCode { } else { // C-C-C-Combo breaker! 26 }; - let mut result = vec![6i32]; - let mut pos: i32 = (ver as i32) * 4 + 10; - for _ in 0 .. numalign - 1 { - result.insert(1, pos); - pos -= step; - } + let start = (ver as i32) * 4 + 10; + let mut result: Vec = (0 .. numalign - 1).map(|i| start - i * step).collect(); + result.push(6); + result.reverse(); result } }