Folder and input renaming
This commit is contained in:
parent
076ca288f1
commit
7a59369808
|
@ -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;
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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.
|
|
@ -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});
|
|
@ -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
|
|
@ -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)});
|
Reference in New Issue