mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 06:03:09 -05:00
062-065 completed
This commit is contained in:
parent
b22b03d9f6
commit
2e5efa8f64
4 changed files with 10 additions and 10 deletions
|
@ -47,7 +47,7 @@ pub fn main() void {
|
||||||
// return it from the for loop.
|
// return it from the for loop.
|
||||||
const current_lang: ?[]const u8 = for (langs) |lang| {
|
const current_lang: ?[]const u8 = for (langs) |lang| {
|
||||||
if (lang.len == 3) break lang;
|
if (lang.len == 3) break lang;
|
||||||
};
|
} else null;
|
||||||
|
|
||||||
if (current_lang) |cl| {
|
if (current_lang) |cl| {
|
||||||
print("Current language: {s}\n", .{cl});
|
print("Current language: {s}\n", .{cl});
|
||||||
|
|
|
@ -128,8 +128,8 @@ pub fn main() void {
|
||||||
// wanted for this Food.
|
// wanted for this Food.
|
||||||
//
|
//
|
||||||
// Please return this Food from the loop.
|
// Please return this Food from the loop.
|
||||||
break;
|
break food;
|
||||||
};
|
} else menu[0];
|
||||||
// ^ Oops! We forgot to return Mac & Cheese as the default
|
// ^ Oops! We forgot to return Mac & Cheese as the default
|
||||||
// Food when the requested ingredients aren't found.
|
// Food when the requested ingredients aren't found.
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ pub fn main() void {
|
||||||
//
|
//
|
||||||
// If there was no overflow at all while adding 5 to a, what value would
|
// If there was no overflow at all while adding 5 to a, what value would
|
||||||
// 'my_result' hold? Write the answer in into 'expected_result'.
|
// 'my_result' hold? Write the answer in into 'expected_result'.
|
||||||
const expected_result: u8 = ???;
|
const expected_result: u8 = @as(u8, a) + @as(u8, b);
|
||||||
print(". Without overflow: {b:0>8}. ", .{expected_result});
|
print(". Without overflow: {b:0>8}. ", .{expected_result});
|
||||||
|
|
||||||
print("Furthermore, ", .{});
|
print("Furthermore, ", .{});
|
||||||
|
@ -78,6 +78,6 @@ pub fn main() void {
|
||||||
// Now it's your turn. See if you can fix this attempt to use
|
// Now it's your turn. See if you can fix this attempt to use
|
||||||
// this builtin to reverse the bits of a u8 integer.
|
// this builtin to reverse the bits of a u8 integer.
|
||||||
const input: u8 = 0b11110000;
|
const input: u8 = 0b11110000;
|
||||||
const tupni: u8 = @bitReverse(input, tupni);
|
const tupni: u8 = @bitReverse(input);
|
||||||
print("{b:0>8} backwards is {b:0>8}.\n", .{ input, tupni });
|
print("{b:0>8} backwards is {b:0>8}.\n", .{ input, tupni });
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub fn main() void {
|
||||||
// Oops! We cannot leave the 'me' and 'myself' fields
|
// Oops! We cannot leave the 'me' and 'myself' fields
|
||||||
// undefined. Please set them here:
|
// undefined. Please set them here:
|
||||||
narcissus.me = &narcissus;
|
narcissus.me = &narcissus;
|
||||||
narcissus.??? = ???;
|
narcissus.myself = &narcissus;
|
||||||
|
|
||||||
// This determines a "peer type" from three separate
|
// This determines a "peer type" from three separate
|
||||||
// references (they just happen to all be the same object).
|
// references (they just happen to all be the same object).
|
||||||
|
@ -70,7 +70,7 @@ pub fn main() void {
|
||||||
//
|
//
|
||||||
// The fix for this is very subtle, but it makes a big
|
// The fix for this is very subtle, but it makes a big
|
||||||
// difference!
|
// difference!
|
||||||
const Type2 = narcissus.fetchTheMostBeautifulType();
|
const Type2 = Narcissus.fetchTheMostBeautifulType();
|
||||||
|
|
||||||
// Now we print a pithy statement about Narcissus.
|
// Now we print a pithy statement about Narcissus.
|
||||||
print("A {s} loves all {s}es. ", .{
|
print("A {s} loves all {s}es. ", .{
|
||||||
|
@ -109,15 +109,15 @@ pub fn main() void {
|
||||||
// Please complete these 'if' statements so that the field
|
// Please complete these 'if' statements so that the field
|
||||||
// name will not be printed if the field is of type 'void'
|
// name will not be printed if the field is of type 'void'
|
||||||
// (which is a zero-bit type that takes up no space at all!):
|
// (which is a zero-bit type that takes up no space at all!):
|
||||||
if (fields[0].??? != void) {
|
if (fields[0].type != void) {
|
||||||
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[0].name});
|
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[0].name});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields[1].??? != void) {
|
if (fields[1].type != void) {
|
||||||
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[1].name});
|
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[1].name});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fields[2].??? != void) {
|
if (fields[2].type != void) {
|
||||||
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[2].name});
|
print(" {s}", .{@typeInfo(Narcissus).Struct.fields[2].name});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue