Day 3 initial working pass

main
Joey Hines 2022-12-03 10:32:27 -07:00
parent 89ff0eda4e
commit 8da7201ca1
Signed by: joeyahines
GPG Key ID: 995E531F7A569DDB
4 changed files with 378 additions and 1 deletions

View File

@ -12,7 +12,7 @@ pub fn build(b: *std.build.Builder) void {
const mode = b.standardReleaseOptions();
const days = [_]u8{1, 2};
const days = [_]u8{1, 2, 3};
for (days) |day| {
const dayPath = b.fmt("src/day{}.zig", .{day});

300
inputs/day3.txt 100644
View File

@ -0,0 +1,300 @@
dtddvvhwttHJhwdhJPddhwJGppmGjgpQgTjQplQpTljwpg
BfzSzRSVVMVNRMDDNBSNSnfBmbrglGQbmNpQggFjpgpbQlQb
ZSBffLnVZdCCPJjhhL
RGCZpWWWFlHQQbgvFssg
jLnMzjnrnjjNjhrjdwbHscsVVgDVQPvPwh
nfJnLMLzjJMtnjNnnBbZtBWBqqbTTTBRpT
nddlhBtqTBqTVSlBtmCmVcRVmZggfWbcZc
jDjvPrPSNPwrDNRWbbgWCjRRCcWm
DzDwSpFrvrvFPQLzQnsqztBthTJnGJqlsJ
gssGmzwgRgsNmTsqgDnDJnbDHHhhzFdDDh
WQVFjMWrVQrVvVVjVctSSLSMZhnJZPBnbdnhbnHZZBDJBh
VCtcccVQLrfvrSlGmfTfNgfmlFgm
DsmfsBbNNZhDWsbmWmNbbPDHLFjcctjjGcnZGzncnctcGH
SwVQJrjVwpgSVRpjpVRrlTMCFFCLCFFcHzzGMcHrtHHH
ppVwTwSwpwvSlSlJTjVVbPhsvvBssWsNfsqWPvWs
BJwqwJtqqDDDrGDnPFzPFfpphD
TgZscCHQLSHgZcfMzpjFFjzsshfj
LcNlTVQCCVLLZTLNvpRtpvBBvRJmNB
bDBGQBBCTTNPGPPwPzcHfVHrDtLWLVrWVjjHWr
gpssqqsqlMFfLZQWftjVpr
lvqqFMRlFcQvbzCNCG
fhhMDdPhWMJMWvhhSfwRSGlzFbSFNlzw
LcqTCqcgZqjTggVjcwbFRwbDBTzbRGRwT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svmdSPPVccmSJcSpGBWWWbBHfWWnfttJWnWJpJ
wDzqhjzmqRzDRwqDzNDbWtjWBBBtGbtHpHnnBf
zglRhDqqDZgRNmZQVCdcCPQvvdZv
RpVjRgvFjGBNWtBWFDtt
dcqQwlqMMsCLLfbgQmtD
snlgzsggTzSTSJTr
dLHhDdtlMngFcFsFLFzzsj
vWRGGRVrrWvvGQQJBRsmQzmsqnffqcNfNcfz
vSRVJBVBwTvWTnHphTgDgtMpDl
bvvGnnJbfPmfdgJJSVtwwCpTScVfNpSC
sjsZWDqBqqMRZsDjbWMVwtwNNcNtScRHpRRttp
hzhDqqWDzZzDZzZLQPJPdPnPvlrbGdlnFQ
PwWHTwzFvNHsNzmmMwzNWGQrCqCFjpZbpnGqrqnpbr
gRVRgJRJlDLSJddDccQVrtZnCqjndnrZdnqnqpdq
chhgSSJfQhRRcSSSSBLVfzmzHTNzMNsTNWHMMvMP
lftqSpBSvhlDBDlhBSczQGmcFMcMVVFMmGFWsm
rHLHTNdggsLLnwLHbTTgdrTMPPmMGWZGQQMzQVQFZQGM
gbJnrHHjnbrgLrRrHpBJvSBDDsfJsDtstq
dBTtFLTtVmpdLhMprSRSWMRSMR
QvJvQbjbCgCQRBhzzRsNWNBC
bjgGqQGbQnjGQgnQgbGgjJnDLHLdfPVtdDmLZdBFVVZttdTf

77
src/day3.zig 100644
View File

@ -0,0 +1,77 @@
const std = @import("std");
pub fn find_intersection2(array1: []u8, array2: []u8) ?u8 {
for (array1) |item1| {
for (array2) |item2| {
if (item1 == item2) {
return item2;
}
}
}
return null;
}
pub fn find_intersection3(array1: []u8, array2: []u8, array3: []u8) ?u8 {
for (array1) |item1| {
for (array2) |item2| {
for (array3) |item3| {
if ((item1 == item2) and (item2 == item3)) {
return item3;
}
}
}
}
return null;
}
pub fn get_priority_value(val: u8) u32 {
if (val >= 'a') {
return @intCast(u32, val) - 'a' + 1;
}
else {
return @intCast(u32, val) - 'A' + 27;
}
}
pub fn main() !void {
var file = try std.fs.cwd().openFile("inputs/day3.txt", .{});
defer file.close();
var buf_reader = std.io.bufferedReader(file.reader());
var in_stream = buf_reader.reader();
var buf: [1024]u8 = undefined;
var pirority_sum1: u32 = 0;
var pirority_sum2: u32 = 0;
var line_number: u32 = 0;
var group: [3][1024]u8 = [3][1024]u8 {[_]u8{0} ** 1024, [_]u8{0} ** 1024, [_]u8{0} ** 1024};
while (try in_stream.readUntilDelimiterOrEof(&buf, '\n')) |line| {
const len = line.len;
var compartment1 = line[0..len/2];
var compartment2 = line[len/2..];
const intersection = find_intersection2(compartment1, compartment2).?;
pirority_sum1 += get_priority_value(intersection);
std.mem.copy(u8, &group[line_number % 3], line);
if ((line_number % 3) == 2) {
const intersection2 = find_intersection3(&group[0], &group[1], &group[2]).?;
pirority_sum2 += get_priority_value(intersection2);
std.mem.set([1024]u8, &group, [_]u8{0}**1024);
}
line_number += 1;
}
std.debug.print("PART1 Sum of all priorties is: {}\n", .{pirority_sum1});
std.debug.print("PART2 Sum of all priorties is: {}\n", .{pirority_sum2});
}

0
src/utils.zig 100644
View File