From 44311378add75eebf87d41607fa8fb12cf5fa2e5 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 7 Mar 2021 20:49:41 +0100 Subject: solved problem 6,7 --- src/main.zig | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src') 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(); } -- cgit v1.2.3