first commit
This commit is contained in:
commit
83f75486a1
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,32 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
// read the input file
|
||||||
|
const input = try std.fs.cwd().openFile("input", .{});
|
||||||
|
defer input.close();
|
||||||
|
|
||||||
|
var buf_reader = std.io.bufferedReader(input.reader());
|
||||||
|
var in_stream = buf_reader.reader();
|
||||||
|
var buf: [1024]u8 = undefined;
|
||||||
|
|
||||||
|
var cal : i32 = 0;
|
||||||
|
var max_cal : i32 = 0;
|
||||||
|
|
||||||
|
while (try in_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
|
||||||
|
for (line) |char| {
|
||||||
|
if (!std.ascii.isWhitespace(char)) { // Contains a number
|
||||||
|
const curr_cal = try std.fmt.parseInt(i32, line, 10);
|
||||||
|
cal += curr_cal;
|
||||||
|
break; // else branch not evaluated
|
||||||
|
}
|
||||||
|
} else { // All characters are whitelines
|
||||||
|
max_cal = @max(max_cal, cal);
|
||||||
|
cal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std.debug.print("Maximum Calories: {}\n", .{max_cal});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
// read the input file
|
||||||
|
const input = try std.fs.cwd().openFile("input", .{});
|
||||||
|
defer input.close();
|
||||||
|
|
||||||
|
var buf_reader = std.io.bufferedReader(input.reader());
|
||||||
|
var in_stream = buf_reader.reader();
|
||||||
|
var buf: [1024]u8 = undefined;
|
||||||
|
|
||||||
|
var cal : i32 = 0;
|
||||||
|
var max_cal : [3]i32 = .{0, 0, 0};
|
||||||
|
|
||||||
|
while (try in_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
|
||||||
|
for (line) |char| {
|
||||||
|
if (!std.ascii.isWhitespace(char)) { // Contains a number
|
||||||
|
cal += std.fmt.parseInt(i32, line, 10) catch break;
|
||||||
|
break; // else branch not evaluated
|
||||||
|
}
|
||||||
|
} else { // All characters are whitelines
|
||||||
|
for (max_cal) |*max_i| {
|
||||||
|
if (cal > max_i.*) {
|
||||||
|
const aux = max_i.*;
|
||||||
|
max_i.* = cal;
|
||||||
|
cal = aux;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var max_total : i32 = 0;
|
||||||
|
for (max_cal) |max_i| {
|
||||||
|
std.debug.print("Max : {}\n", .{max_i});
|
||||||
|
max_total += max_i;
|
||||||
|
}
|
||||||
|
|
||||||
|
std.debug.print("Maximum Calories: {}\n", .{max_total});
|
||||||
|
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,37 @@
|
||||||
|
const std = @import("std");
|
||||||
|
|
||||||
|
const mem = std.mem;
|
||||||
|
const fmt = std.fmt;
|
||||||
|
|
||||||
|
const print = std.debug.print;
|
||||||
|
|
||||||
|
const input = @embedFile("input");
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var total_points: u32 = 0;
|
||||||
|
// Split the input
|
||||||
|
var input_iter = mem.split(u8, input, "\n");
|
||||||
|
while (input_iter.next()) |line| {
|
||||||
|
// Input ends with an empty line
|
||||||
|
if (line.len == 0) continue;
|
||||||
|
// Converting character code to points
|
||||||
|
const op: i4 = @intCast(i4, line[0] -| 64);
|
||||||
|
const me: i4 = @intCast(i4, line[2] -| 87);
|
||||||
|
|
||||||
|
//rock - paper = -1 WIN
|
||||||
|
//rock - scissors = -2 LOSE
|
||||||
|
//paper - rock = 1 LOSE
|
||||||
|
//paper - scissors = -1 WIN
|
||||||
|
//scissors - rock = 2 WIN
|
||||||
|
//scissors - paper = 1 LOSE
|
||||||
|
|
||||||
|
switch (op - me) {
|
||||||
|
-1, 2 => total_points += 6,
|
||||||
|
-2, 1 => total_points += 0,
|
||||||
|
else => total_points += 3,
|
||||||
|
}
|
||||||
|
|
||||||
|
total_points += @intCast(u4, me);
|
||||||
|
}
|
||||||
|
print("{}\n", .{total_points});
|
||||||
|
}
|
Loading…
Reference in New Issue