more idiomatic full range loops
This commit is contained in:
parent
e412d63914
commit
377682bd1a
|
@ -52,7 +52,7 @@ pub fn main() anyerror!void {
|
||||||
var bestkey: u8 = 0;
|
var bestkey: u8 = 0;
|
||||||
var bestscore: u32 = 0;
|
var bestscore: u32 = 0;
|
||||||
var key: u8 = 0;
|
var key: u8 = 0;
|
||||||
while (true) {
|
while (true) : (key += 1) {
|
||||||
decrypt(plaintext, ciphertext, key);
|
decrypt(plaintext, ciphertext, key);
|
||||||
const s = score(plaintext);
|
const s = score(plaintext);
|
||||||
if (s > bestscore) {
|
if (s > bestscore) {
|
||||||
|
@ -60,7 +60,7 @@ pub fn main() anyerror!void {
|
||||||
bestscore = s;
|
bestscore = s;
|
||||||
}
|
}
|
||||||
key +%= 1;
|
key +%= 1;
|
||||||
if (key == 0) {
|
if (key == std.math.maxInt(u8)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub fn main() anyerror!void {
|
||||||
var plaintext = try allocator.alloc(u8, ciphertext.len);
|
var plaintext = try allocator.alloc(u8, ciphertext.len);
|
||||||
defer allocator.free(plaintext);
|
defer allocator.free(plaintext);
|
||||||
var key: u8 = 0;
|
var key: u8 = 0;
|
||||||
while (true) {
|
while (true) : (key += 1) {
|
||||||
decrypt(plaintext, ciphertext, key);
|
decrypt(plaintext, ciphertext, key);
|
||||||
const s = score(plaintext);
|
const s = score(plaintext);
|
||||||
if (s > bestscore) {
|
if (s > bestscore) {
|
||||||
|
@ -62,8 +62,7 @@ pub fn main() anyerror!void {
|
||||||
std.mem.copy(u8, bestplaintext.items, plaintext);
|
std.mem.copy(u8, bestplaintext.items, plaintext);
|
||||||
bestscore = s;
|
bestscore = s;
|
||||||
}
|
}
|
||||||
key +%= 1;
|
if (key == std.math.maxInt(u8)) {
|
||||||
if (key == 0) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue