const std = @import("std"); const print = std.debug.warn; fn p1() void { var i: usize = 0; var sum: usize = 0; while (i < 1000) : (i += 1) { if (i % 3 == 0) { sum += i; } else if (i % 5 == 0) { sum += i; } } std.debug.warn("{}\n", .{sum}); } fn p2() void { const size: usize = 35; var array: [size]usize = undefined; for (array) |_, i| { array[i] = 0; } array[0] = 1; array[1] = 2; var i: usize = 2; while (i < size) : (i += 1) { array[i] = array[i - 1] + array[i - 2]; } i = 0; var sum: usize = 0; while (array[i] < 4_000_000) : (i += 1) { if (array[i] % 2 == 0) sum += array[i]; } std.debug.warn("{}\n", .{sum}); } fn is_prime(k: usize) bool { var i: usize = 2; var divided: bool = false; while (i < k) : (i += 1) { if (k % i == 0) { divided = true; break; } } return !divided; } fn p3() void { const size: usize = 5000; 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; } } const n: usize = 600851475143; //const n: usize = 13195; var biggest: usize = 0; for (primes) |prime| { if (n % prime == 0) { biggest = prime; } } std.debug.warn("{}\n", .{biggest}); } fn p4() !void { var i: usize = 0; var j: usize = 0; var str: [6]u8 = undefined; var largest: usize = 0; while (i < 1000) : (i += 1) { j = 0; while (j < 1000) : (j += 1) { _ = try std.fmt.bufPrint(&str, "{}", .{i * j}); if (i * j > largest and str[0] == str[5] and str[1] == str[4] and str[2] == str[3]) { largest = i * j; } } } 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; } } } 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(); //p6(); //p7(); p8(); }