Minor speed tweaks for day 4

This commit is contained in:
2019-12-04 23:30:26 +00:00
parent be0c611f0d
commit 3ddda35eec

View File

@@ -8,7 +8,7 @@ const last = 643603;
// - [x] Two adjacent digits are the same (like 22 in 122345).
// - [x] Going from left to right, the digits never decrease; they only ever increase or stay the same (like 111123 or 135679).
fn tests1(num: i32, str: []u8) bool {
inline fn tests1(num: i32, str: []u8) bool {
if (str[0] > str[1] or str[1] > str[2] or
str[2] > str[3] or str[3] > str[4] or
str[4] > str[5]) return false;
@@ -18,7 +18,7 @@ fn tests1(num: i32, str: []u8) bool {
str[4] == str[5];
}
fn tests2(num: i32, str: []u8) bool {
inline fn tests2(num: i32, str: []u8) bool {
if (str[0] == str[1] and str[1] != str[2]) return true; // [0 1]2 3 4 5
if (str[1] == str[2] and str[0] != str[1] and str[2] != str[3]) return true; // 0[1 2]3 4 5
if (str[2] == str[3] and str[1] != str[2] and str[3] != str[4]) return true; // 0 1[2 3]4 5
@@ -41,13 +41,12 @@ pub fn main() anyerror!void {
count1 += 1;
if (tests2(i, numStr)) {
std.debug.warn("Match: {}\n", i);
count2 += 1;
}
}
}
std.debug.warn(" 012345\n");
//std.debug.warn(" 012345\n");
std.debug.warn("Part 1: matches: {}\n", count1);
std.debug.warn("Part 2: matches: {}\n", count2);