From babceab9f3f5bdc5365a06e9effdb4acc4e24a02 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 7 Mar 2021 18:46:23 +0100 Subject: solved problem 4 --- src/main.zig | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 3096ab3..f6e3ec2 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,7 +1,5 @@ const std = @import("std"); const print = std.debug.warn; -// spalf -// mypassword fn p1() void { var i: usize = 0; @@ -76,26 +74,30 @@ fn p3() void { } } -fn p4() void { +fn p4() !void { var i: usize = 0; var j: usize = 0; - var str: [10]u8 = undefined; - while (i < 100) : (i += 1) { + var str: [6]u8 = undefined; + var largest: usize = 0; + while (i < 1000) : (i += 1) { j = 0; - while (j < 100) : (j += 1) { - //std.fmt.bufPrint(&str, "{}", .{i * j}) catch unreachable; - //if (std.fmt.bufPrint(&str, "{}", .{i*j})) |ret| { - // std.debug.warn("{}\n", .{str}); - //} else | err | { - //} - //var str: parseInt(usize, i*j) + 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}); } -pub fn main() void { +pub fn main() !void { //p1(); //p2(); //p3(); - p4(); + _ = try p4(); } -- cgit v1.2.3