more idiomatic full range loops

master
Thomas Lindner 2022-02-09 22:36:52 +01:00
parent e412d63914
commit 377682bd1a
2 changed files with 4 additions and 5 deletions

View File

@ -52,7 +52,7 @@ pub fn main() anyerror!void {
var bestkey: u8 = 0;
var bestscore: u32 = 0;
var key: u8 = 0;
while (true) {
while (true) : (key += 1) {
decrypt(plaintext, ciphertext, key);
const s = score(plaintext);
if (s > bestscore) {
@ -60,7 +60,7 @@ pub fn main() anyerror!void {
bestscore = s;
}
key +%= 1;
if (key == 0) {
if (key == std.math.maxInt(u8)) {
break;
}
}

View File

@ -54,7 +54,7 @@ pub fn main() anyerror!void {
var plaintext = try allocator.alloc(u8, ciphertext.len);
defer allocator.free(plaintext);
var key: u8 = 0;
while (true) {
while (true) : (key += 1) {
decrypt(plaintext, ciphertext, key);
const s = score(plaintext);
if (s > bestscore) {
@ -62,8 +62,7 @@ pub fn main() anyerror!void {
std.mem.copy(u8, bestplaintext.items, plaintext);
bestscore = s;
}
key +%= 1;
if (key == 0) {
if (key == std.math.maxInt(u8)) {
break;
}
}