diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-03-07 18:46:23 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-03-07 18:46:23 +0100 |
commit | babceab9f3f5bdc5365a06e9effdb4acc4e24a02 (patch) | |
tree | ca024fa0b85fdd3a8055a3b95c4caa231ec181f2 /src/main.zig | |
parent | 75dc4585f943a579cdc0fcdc415afb8d7e40468c (diff) |
solved problem 4
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 30 |
1 files changed, 16 insertions, 14 deletions
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(); } |