WIP: implement part 2
This commit is contained in:
parent
89d248d3b8
commit
34f9fff423
1 changed files with 30 additions and 9 deletions
|
|
@ -17,23 +17,44 @@ pub fn run(_: std.mem.Allocator) !void {
|
||||||
|
|
||||||
std.debug.print("{d} to {d}\n", .{start, end});
|
std.debug.print("{d} to {d}\n", .{start, end});
|
||||||
|
|
||||||
outer: for (start..end+1) |id| {
|
for (start..end+1) |id| {
|
||||||
|
std.debug.print("-- Checking {d} --\n", .{id});
|
||||||
|
|
||||||
// IDs smaller than 10 cannot possibly have repeated digits
|
// IDs smaller than 10 cannot possibly have repeated digits
|
||||||
if (id / 10 == 0) continue;
|
if (id / 10 == 0) {
|
||||||
|
std.debug.print("Skipping {d}\n", .{id});
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const len = getLen(id);
|
const len = getLen(id);
|
||||||
// Uneven numbers cannot consist of 2 sequences
|
inner: for (2..len + 1) |divisor| {
|
||||||
if (len % 2 == 1) continue;
|
if (len % divisor != 0) continue;
|
||||||
|
|
||||||
for (0..len / 2) |i| {
|
std.debug.print("divisor = {d}\n", .{divisor});
|
||||||
const a = getDigit(id, i);
|
|
||||||
const b = getDigit(id, i + len / 2);
|
const window_len = len / divisor;
|
||||||
if (a != b) {
|
|
||||||
continue :outer;
|
std.debug.print("window_len = {d}\n", .{window_len});
|
||||||
|
|
||||||
|
for (0..window_len) |i| {
|
||||||
|
const a = getDigit(id, i);
|
||||||
|
std.debug.print("a = {d}\n", .{a});
|
||||||
|
for (1..divisor) |n| {
|
||||||
|
const b = getDigit(id, i + window_len * n);
|
||||||
|
std.debug.print("b = {d}\n", .{b});
|
||||||
|
if (a != b) {
|
||||||
|
continue :inner;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// If we get here, it means id is a valid cadidate
|
||||||
|
std.debug.print("result = {d}\n", .{id});
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
accumulator += id;
|
accumulator += id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var buffer: [64]u8 = undefined;
|
var buffer: [64]u8 = undefined;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue