attemps from before

This commit is contained in:
2022-11-25 22:36:13 +01:00
commit 680da5cc2c
17 changed files with 5703 additions and 0 deletions
+70
View File
@@ -0,0 +1,70 @@
const input = @embedFile("input2");
const std = @import("std");
pub fn main() !void{
var horizontal: usize = 0;
var depth: usize = 0;
var aim: usize = 0;
var iter = std.mem.tokenize(u8, input, "\n "); // You can split on 2 delimeters, by adding them to the string
while(iter.next())|direction|{
var value = try std.fmt.parseInt(usize, iter.next().?, 10);
if(std.mem.eql(u8, direction, "up")){ aim -= value; }
if(std.mem.eql(u8, direction, "down")){ aim += value; }
if(std.mem.eql(u8, direction, "forward")){
horizontal += value;
depth += (aim * value);
}
}
std.debug.print("result: {}", .{depth * horizontal});
}
test "Part 1"{
var horizontal: usize = 0;
var depth: usize = 0;
var iter = std.mem.tokenize(u8, input, "\n "); // You can split on 2 delimeters, by adding them to the string
while(iter.next())|direction|{
var value = try std.fmt.parseInt(usize, iter.next().?, 10);
if(std.mem.eql(u8, direction, "forward")){ horizontal += value; }
if(std.mem.eql(u8, direction, "up")){ depth -= value; }
if(std.mem.eql(u8, direction, "down")){ depth += value; }
}
std.testing.expect(1762050 == (depth * horizontal));
}
test "part 2"{
var horizontal: usize = 0;
var depth: usize = 0;
var aim: usize = 0;
var iter = std.mem.tokenize(u8, input, "\n "); // You can split on 2 delimeters, by adding them to the string
//First token is the direction
while(iter.next())|direction|{
var value = try std.fmt.parseInt(usize, iter.next().?, 10);
if(std.mem.eql(u8, direction, "up")){ aim -= value; }
if(std.mem.eql(u8, direction, "down")){ aim += value; }
if(std.mem.eql(u8, direction, "forward")){
horizontal += value;
depth += (aim * value);
}
}
std.testing.expect(1855892637 == (depth * horizontal));
}
+1000
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2