From 7a59369808e9294ee15b0b8bd8676e4195a154bf Mon Sep 17 00:00:00 2001 From: Dendy Date: Thu, 8 Dec 2022 17:22:18 +0100 Subject: [PATCH] Folder and input renaming --- {1 => 01}/1.zig | 2 +- {1 => 01}/2.zig | 8 ++++---- 1/input.asc => 01/input | 0 {2 => 02}/1.zig | 6 +++--- {2 => 02}/2.zig | 4 ++-- 2/input.asc => 02/input | 0 {3 => 03}/1-2.zig | 2 +- 3/input.asc => 03/input | 0 {4 => 04}/1-2.zig | 11 +++++------ 4/input.asc => 04/input | 0 {5 => 05}/1-2.zig | 7 +++---- 5/input.asc => 05/input | 0 {6 => 06}/1-2.zig | 2 +- 6/input.asc => 06/input | 0 14 files changed, 20 insertions(+), 22 deletions(-) rename {1 => 01}/1.zig (91%) rename {1 => 01}/2.zig (91%) rename 1/input.asc => 01/input (100%) rename {2 => 02}/1.zig (92%) rename {2 => 02}/2.zig (94%) rename 2/input.asc => 02/input (100%) rename {3 => 03}/1-2.zig (98%) rename 3/input.asc => 03/input (100%) rename {4 => 04}/1-2.zig (82%) rename 4/input.asc => 04/input (100%) rename {5 => 05}/1-2.zig (93%) rename 5/input.asc => 05/input (100%) rename {6 => 06}/1-2.zig (96%) rename 6/input.asc => 06/input (100%) diff --git a/1/1.zig b/01/1.zig similarity index 91% rename from 1/1.zig rename to 01/1.zig index 3f93071..b4465c4 100644 --- a/1/1.zig +++ b/01/1.zig @@ -1,7 +1,7 @@ const std = @import("std"); pub fn main() void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); var iter = std.mem.split(u8, input, "\n"); var max: usize = 0; diff --git a/1/2.zig b/01/2.zig similarity index 91% rename from 1/2.zig rename to 01/2.zig index b360da0..85bc201 100644 --- a/1/2.zig +++ b/01/2.zig @@ -4,7 +4,7 @@ const std = @import("std"); // to make it as efficient as possible. pub fn main() !void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); // Putting part 1's solution as an extra :P std.debug.print("Part 1's solution: {}\n", .{sumTopNElves(input, 1)}); @@ -28,9 +28,9 @@ pub fn sumTopNElves(input: []const u8, comptime cant: usize) usize { // maxArr changed, update what is the smallest index var advance: usize = 1; - while (advance < cant) : (advance += 1) { + while (advance < cant) : (advance += 1) { // Advance and wrap around - const i = (min_i + advance)%cant; + const i = (min_i + advance) % cant; if (maxArr[i] < maxArr[min_i]) min_i = i; } @@ -59,7 +59,7 @@ const ElfIterator = struct { pub fn next(self: *ElfIterator) ?usize { var res: usize = 0; - while(self.iter.next()) |calories| { + while (self.iter.next()) |calories| { // If non numeric assume EOF (End Of elF) res += std.fmt.parseInt(usize, calories, 10) catch return res; } diff --git a/1/input.asc b/01/input similarity index 100% rename from 1/input.asc rename to 01/input diff --git a/2/1.zig b/02/1.zig similarity index 92% rename from 2/1.zig rename to 02/1.zig index 811e0e1..d20e1af 100644 --- a/2/1.zig +++ b/02/1.zig @@ -1,7 +1,7 @@ const std = @import("std"); pub fn main() void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); var iter = std.mem.split(u8, input, "\n"); var totalPoints: usize = 0; @@ -19,7 +19,7 @@ pub fn main() void { // Points per shape chosen is easy. // {0,1,2} + 1 == {1,2,3} // which is what we want. - const shapePoints = me+1; + const shapePoints = me + 1; // Now this is a bit more complex. // We notice that 'them - me' gives: @@ -52,7 +52,7 @@ pub fn main() void { // // Now we multiply by three so '(2-(result+4)%3)*3' // and boom, points per result per match. - const resultPoints = (2-((4 + them) - me)%3)*3; + const resultPoints = (2 - ((4 + them) - me) % 3) * 3; totalPoints += resultPoints + shapePoints; } diff --git a/2/2.zig b/02/2.zig similarity index 94% rename from 2/2.zig rename to 02/2.zig index 82efbf9..9b1aab0 100644 --- a/2/2.zig +++ b/02/2.zig @@ -1,7 +1,7 @@ const std = @import("std"); pub fn main() void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); var iter = std.mem.split(u8, input, "\n"); var totalPoints: usize = 0; @@ -52,7 +52,7 @@ pub fn main() void { // win(2) {2,0,1} {1,2,0} // // Now it's just a matter of adding one to that - const shapePoints = ((them + result + 2)%3) + 1; + const shapePoints = ((them + result + 2) % 3) + 1; totalPoints += resultPoints + shapePoints; } diff --git a/2/input.asc b/02/input similarity index 100% rename from 2/input.asc rename to 02/input diff --git a/3/1-2.zig b/03/1-2.zig similarity index 98% rename from 3/1-2.zig rename to 03/1-2.zig index a90c464..bf91e18 100644 --- a/3/1-2.zig +++ b/03/1-2.zig @@ -7,7 +7,7 @@ const Iterator = std.mem.SplitIterator(u8); const stepFnType = *const fn (*Iterator, []string) ?[]string; pub fn main() void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); // The fundamental difference lies in the way of processing the file, // so we abstract that into a function to be able to pass its pointer. diff --git a/3/input.asc b/03/input similarity index 100% rename from 3/input.asc rename to 03/input diff --git a/4/1-2.zig b/04/1-2.zig similarity index 82% rename from 4/1-2.zig rename to 04/1-2.zig index 76564d7..b13d9d1 100644 --- a/4/1-2.zig +++ b/04/1-2.zig @@ -7,10 +7,10 @@ pub fn main() void { var totalFit: usize = 0; var totalAabb: usize = 0; - const input = @embedFile("input.asc"); + const input = @embedFile("input"); var iter = std.mem.split(u8, input, "\n"); - while(iter.next()) |line| { + while (iter.next()) |line| { if (line.len <= 0) continue; ////////////////// @@ -18,11 +18,11 @@ pub fn main() void { //////////////// const delim = "-,-"; - if ((delim.len+1)&1 != 0) @panic("Amount of nums should always be even"); - var nums = [_]u8{undefined} ** (delim.len+1); + if ((delim.len + 1) & 1 != 0) @panic("Amount of nums should always be even"); + var nums = [_]u8{undefined} ** (delim.len + 1); var startIdx: usize = 0; - inline for(nums) |_,i| { + inline for (nums) |_, i| { // Get the number const numstr = if (i < delim.len) std.mem.sliceTo(line[startIdx..], delim[i]) @@ -35,7 +35,6 @@ pub fn main() void { if (fitTest(nums[0..2], nums[2..4])) totalFit += 1; if (aabbTest(nums[0..2], nums[2..4])) totalAabb += 1; - } std.debug.print("Part 1: {}\n", .{totalFit}); diff --git a/4/input.asc b/04/input similarity index 100% rename from 4/input.asc rename to 04/input diff --git a/5/1-2.zig b/05/1-2.zig similarity index 93% rename from 5/1-2.zig rename to 05/1-2.zig index 0f5e8a3..1b1a91c 100644 --- a/5/1-2.zig +++ b/05/1-2.zig @@ -17,14 +17,13 @@ pub fn main() void { defer arena.deinit(); const allocator = arena.allocator(); - const input = @embedFile("input.asc"); + const input = @embedFile("input"); - std.debug.print("Part 1: {s}\n", .{crane900X(input,moveAppend, allocator)}); - std.debug.print("Part 2: {s}\n", .{crane900X(input,moveAppendSlice, allocator)}); + std.debug.print("Part 1: {s}\n", .{crane900X(input, moveAppend, allocator)}); + std.debug.print("Part 2: {s}\n", .{crane900X(input, moveAppendSlice, allocator)}); } fn crane900X(input: []const u8, moveFn: moveFnType, allocator: std.mem.Allocator) []const u8 { - var iter = std.mem.split(u8, input, "\n"); // Parses the header with the states and advances the counter diff --git a/5/input.asc b/05/input similarity index 100% rename from 5/input.asc rename to 05/input diff --git a/6/1-2.zig b/06/1-2.zig similarity index 96% rename from 6/1-2.zig rename to 06/1-2.zig index 64f367a..e10e093 100644 --- a/6/1-2.zig +++ b/06/1-2.zig @@ -1,7 +1,7 @@ const std = @import("std"); pub fn main() void { - const input = @embedFile("input.asc"); + const input = @embedFile("input"); std.debug.print("Part 1: {}\n", .{findDisctinctSubstrIdx(input, 4)}); std.debug.print("Part 2: {}\n", .{findDisctinctSubstrIdx(input, 14)}); diff --git a/6/input.asc b/06/input similarity index 100% rename from 6/input.asc rename to 06/input