-
Notifications
You must be signed in to change notification settings - Fork 8
Solved day04 & day05 in zig #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Arxcis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more days of Zig 🙏 Loved every line ❤️
| const PassportField = enum(u8) { | ||
| invalid = 0b00000000, | ||
| cid = 0b00000001, | ||
| byr = 0b00000010, | ||
| iyr = 0b00000100, | ||
| eyr = 0b00001000, | ||
| hgt = 0b00010000, | ||
| hcl = 0b00100000, | ||
| ecl = 0b01000000, | ||
| pid = 0b10000000, | ||
| required = 0b11111110, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool enum 😎
| switch(self) { | ||
| .byr, .iyr, .eyr => { | ||
| const value: i32 = try std.fmt.parseInt(i32, field_value, 10); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool enum switch 😎
| or mem.eql(u8, field_value, "blu") | ||
| or mem.eql(u8, field_value, "brn") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool mem.eql() 😄
| var i: usize = 0; | ||
| while(i < field_value.len) : (i += 1) { | ||
| switch (field_value[i]) { | ||
| '0'...'9' => continue, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool shorthand case: 1 ,case: 2, case: 3, case:4, case: 5, case: 6, case: 7, case: 8, case: 9 🥇
| comptime const row_extractor = LineSegmentParser('F', 'B', 127); | ||
| comptime const col_extractor = LineSegmentParser('L', 'R', 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woow 👍
Compile time struct baking? 🍰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hell yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metaprogramming with uniform syntax to the main language was the main drive for zig in the beginning i believe 😄
Note: I made an error merging with my self so there are two commits for "solve day04 in zig" (15cde6c and 7adcaf2). The only consequence is the commit log being polluted by two commits, but the files should be correct.