diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-03-07 20:49:41 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-03-07 20:49:41 +0100 |
commit | 44311378add75eebf87d41607fa8fb12cf5fa2e5 (patch) | |
tree | 479153ccd516adcdfe71568d75963b767f1187f1 /src/main.zig | |
parent | f6084020f9078a850c23b3a2977ac08a4cea9786 (diff) |
solved problem 6,7
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index 8261fa0..3a194fd 100644 --- a/src/main.zig +++ b/src/main.zig @@ -121,10 +121,44 @@ fn p5() void { } } +fn p6() void { + var sum_0: usize = 0; + var sum_1: usize = 0; + + var i: usize = 1; + while (i <= 100) : (i += 1) { + sum_0 += i * i; + sum_1 += i; + } + sum_1 *= sum_1; + + print("{}\n", .{sum_1 - sum_0}); +} + +fn p7() void { + const size: usize = 10_002; + var primes: [size]usize = undefined; + + var i: usize = 1; + var j: usize = 0; + while (j < size) : (i += 1) { + if (is_prime(i)) { + primes[j] = i; + j += 1; + } + } + print("{}\n", .{primes[size - 1]}); +} + +fn p8() void {} + pub fn main() !void { //p1(); //p2(); //p3(); //_ = try p4(); - p5(); + //p5(); + //p6(); + //p7(); + p8(); } |