blob: 68335d761f10edcb0ff79d6e94def1509ab4d599 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
const eql = std.mem.eql;
const parseUnsigned = std.fmt.parseUnsigned;
const print = std.debug.print;
const std = @import("std");
const tokenize = std.mem.tokenize;
pub fn main() !void {
var position = @as(usize, 0);
var depth = @as(usize, 0);
defer print("{}\n", .{ position * depth });
var input = tokenize(@embedFile("input"), "\n");
while (input.next()) |line| {
var command = tokenize(line, " ");
const direction = command.next().?;
const x = try parseUnsigned(usize, command.next().?, 10);
if (eql(u8, direction, "forward"))
position += x
else if (eql(u8, direction, "down"))
depth += x
else if (eql(u8, direction, "up"))
depth -= x
else unreachable;
}
}
|