From f6084020f9078a850c23b3a2977ac08a4cea9786 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 7 Mar 2021 20:37:42 +0100 Subject: solved problem 5 --- src/main.zig | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index f6e3ec2..8261fa0 100644 --- a/src/main.zig +++ b/src/main.zig @@ -67,11 +67,14 @@ fn p3() void { const n: usize = 600851475143; //const n: usize = 13195; + var biggest: usize = 0; for (primes) |prime| { if (n % prime == 0) { - std.debug.warn("{}\n", .{prime}); + biggest = prime; } } + + std.debug.warn("{}\n", .{biggest}); } fn p4() !void { @@ -95,9 +98,33 @@ fn p4() !void { print("{}\n", .{largest}); } +fn p5() void { + var num: usize = 20; + var i: usize = 1; + var j: usize = 0; + var found: bool = false; + + while (i < 1_500_000_000) : (i += 1) { + j = num; + + found = false; + while (j != 0) : (j -= 1) { + if (i % j != 0) { + found = true; + } + } + + if (!found) { + print("{}\n", .{i}); + break; + } + } +} + pub fn main() !void { //p1(); //p2(); //p3(); - _ = try p4(); + //_ = try p4(); + p5(); } -- cgit v1.2.3