Skip to content

Commit 8477985

Browse files
committed
refactor: adjust to zig 0.15.x
1 parent d2d2735 commit 8477985

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1347
-772
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
zig-out/
33

44
**/*/input/**/*.txt
5+
6+
output/

.zigversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.14.0
1+
0.15.1

2023/day1.zig

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ const aoc = @import("aoc");
44
const Allocator = std.mem.Allocator;
55

66
fn strToDigit(s: []const u8) u8 {
7-
const words = [_][]const u8{
8-
"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"
9-
};
10-
for(words, 1..) |word, i| {
7+
const words = [_][]const u8{ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
8+
for (words, 1..) |word, i| {
119
if (std.mem.eql(u8, word, s)) {
1210
// std.debug.print("\n>>> {s}", .{ s });
1311
return @intCast(i);
@@ -19,13 +17,13 @@ fn strToDigit(s: []const u8) u8 {
1917
pub fn part1(_: Allocator, input: []const u8) anyerror!void {
2018
var result: u32 = 0;
2119

22-
var it = std.mem.tokenize(u8, input, "\n");
23-
while(it.next()) |v| {
20+
var it = std.mem.tokenizeAny(u8, input, "\n");
21+
while (it.next()) |v| {
2422
var number: u32 = 0;
2523
var first: u8 = 0;
2624
var last: u8 = 0;
2725

28-
for(0..v.len) |x| {
26+
for (0..v.len) |x| {
2927
const digit = std.fmt.charToDigit(v[x], 10) catch {
3028
continue;
3129
};
@@ -35,7 +33,7 @@ pub fn part1(_: Allocator, input: []const u8) anyerror!void {
3533
}
3634
}
3735

38-
for(0..v.len) |x| {
36+
for (0..v.len) |x| {
3937
const digit = std.fmt.charToDigit(v[v.len - 1 - x], 10) catch 0;
4038
if (digit != 0) {
4139
last = digit;
@@ -49,37 +47,37 @@ pub fn part1(_: Allocator, input: []const u8) anyerror!void {
4947
result += number;
5048
}
5149

52-
std.debug.print("\nResult: {d}", .{ result });
50+
std.debug.print("\nResult: {d}", .{result});
5351
}
5452

5553
pub fn part2(_: Allocator, input: []const u8) anyerror!void {
5654
var result: u32 = 0;
5755

58-
var it = std.mem.tokenize(u8, input, "\n");
59-
while(it.next()) |v| {
56+
var it = std.mem.tokenizeAny(u8, input, "\n");
57+
while (it.next()) |v| {
6058
var number: u32 = 0;
6159
var first: u8 = 0;
6260
var last: u8 = 0;
6361

64-
for(0..v.len) |x| {
62+
for (0..v.len) |x| {
6563
if (v.len >= 3 and x < v.len - 3) {
66-
const word = v[x..x + 3];
64+
const word = v[x .. x + 3];
6765
const digit = strToDigit(word);
6866
if (digit != 0 and first == 0) {
6967
first = digit;
7068
break;
7169
}
7270
}
7371
if (v.len >= 4 and x < v.len - 4) {
74-
const word = v[x..x + 4];
72+
const word = v[x .. x + 4];
7573
const digit = strToDigit(word);
7674
if (digit != 0 and first == 0) {
7775
first = digit;
7876
break;
7977
}
8078
}
8179
if (v.len >= 5 and x < v.len - 5) {
82-
const word = v[x..x + 5];
80+
const word = v[x .. x + 5];
8381
const digit = strToDigit(word);
8482
if (digit != 0 and first == 0) {
8583
first = digit;
@@ -95,7 +93,7 @@ pub fn part2(_: Allocator, input: []const u8) anyerror!void {
9593
}
9694
}
9795

98-
for(0..v.len) |x| {
96+
for (0..v.len) |x| {
9997
var digit = std.fmt.charToDigit(v[v.len - 1 - x], 10) catch 0;
10098
if (digit != 0) {
10199
last = digit;
@@ -138,7 +136,7 @@ pub fn part2(_: Allocator, input: []const u8) anyerror!void {
138136
result += number;
139137
}
140138

141-
std.debug.print("\nResult: {d}", .{ result });
139+
std.debug.print("\nResult: {d}", .{result});
142140
}
143141

144142
pub fn main() !void {

0 commit comments

Comments
 (0)