summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2021-03-07 20:37:42 +0100
committerTom Barrett <tom@tombarrett.xyz>2021-03-07 20:37:42 +0100
commitf6084020f9078a850c23b3a2977ac08a4cea9786 (patch)
tree77d1efe98f6a46ad30fb0b38e85266cdca4734b0 /src
parentbabceab9f3f5bdc5365a06e9effdb4acc4e24a02 (diff)
solved problem 5
Diffstat (limited to 'src')
-rw-r--r--src/main.zig31
1 files changed, 29 insertions, 2 deletions
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();
}