Apply `zig fmt` to exercises

pull/2/head
Will Clardy 4 years ago
parent 97ae27435b
commit 238beb4a2d

@ -19,4 +19,3 @@ const std = @import("std");
fn main() void {
std.debug.print("Hello world!\n", .{});
}

@ -46,6 +46,7 @@ pub fn main() void {
// Use the len property to get the length of the array:
const length = some_primes.???;
std.debug.print("First: {}, Fourth: {}, Length: {}\n",
.{first, fourth, length});
std.debug.print("First: {}, Fourth: {}, Length: {}\n", .{
first, fourth, length,
});
}

@ -34,7 +34,6 @@ pub fn main() void {
// That's all the problems. Let's see our results:
std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });
//
// Keen eyes will notice that we've put 'u' and 's' inside the '{}'
// placeholders in the format string above. This tells the
// print() function to format the values as a UTF-8 character and

@ -14,4 +14,3 @@ pub fn main() void {
std.debug.print("With the discount, the price is ${}.\n", .{price});
}

@ -23,6 +23,5 @@ pub fn main() void {
std.debug.print("The End.\n", .{});
}
//
// Note that "for" loops also work on things called "slices"
// which we'll see later.

@ -23,7 +23,6 @@ pub fn main() void {
std.debug.print("Answer to the Ultimate Question: {}\n", .{answer});
}
//
// Please define the deepThought() function below.
//
// We're just missing a couple things. One thing we're NOT missing is the

@ -18,7 +18,6 @@ pub fn main() void {
});
}
//
// Please give this function the correct input parameter(s).
// You'll need to figure out the parameter name and type that we're
// expecting. The output type has already been specified for you.

@ -14,7 +14,6 @@ pub fn main() void {
std.debug.print("\n", .{});
}
//
// You won't see this every day: a function that takes an array with
// exactly four u16 numbers. This is not how you would normally pass
// an array to a function. We'll learn about slices and pointers in
@ -28,7 +27,6 @@ fn printPowersOfTwo(numbers: [4]u16) ??? {
}
}
//
// This function bears a striking resemblance to twoToThe() in the last
// exercise. But don't be fooled! This one does the math without the aid
// of the standard library!

@ -27,4 +27,3 @@ pub fn main() void {
std.debug.print("I compiled!", .{});
}

@ -37,7 +37,9 @@ pub fn main() void {
// detectProblems() Returns the number or an error.
//
fn makeJustRight(n: u32) MyNumberError!u32 {
return fixTooBig(n) catch |err| { return err; };
return fixTooBig(n) catch |err| {
return err;
};
}
fn fixTooBig(n: u32) MyNumberError!u32 {
@ -65,4 +67,3 @@ fn detectProblems(n: u32) MyNumberError!u32 {
if (n > 20) return MyNumberError.TooBig;
return n;
}

@ -23,7 +23,6 @@ pub fn main() void {
}
fn addFive(n: u32) MyNumberError!u32 {
//
// This function needs to return any error which might come back from detect().
// Please use a "try" statement rather than a "catch".
//
@ -37,4 +36,3 @@ fn detect(n: u32) MyNumberError!u32 {
if (n > 20) return MyNumberError.TooBig;
return n;
}

@ -9,7 +9,6 @@ pub fn main() void {
for (animals) |a| printAnimal(a);
std.debug.print("done.\n", .{});
}
@ -21,9 +20,18 @@ fn printAnimal(animal: u8) void {
std.debug.print(") ", .{}); // <---- how!?
if (animal == 'g'){ std.debug.print("Goat", .{}); return; }
if (animal == 'c'){ std.debug.print("Cat", .{}); return; }
if (animal == 'd'){ std.debug.print("Dog", .{}); return; }
if (animal == 'g') {
std.debug.print("Goat", .{});
return;
}
if (animal == 'c') {
std.debug.print("Cat", .{});
return;
}
if (animal == 'd') {
std.debug.print("Dog", .{});
return;
}
std.debug.print("Unknown", .{});
}

@ -15,7 +15,6 @@
//
const std = @import("std");
//
var counter: u32 = 0;
const MyErr = error{ GetFail, IncFail };

@ -26,9 +26,15 @@ pub fn main() void {
for (operations) |op| {
switch (op) {
1 => { current_value += 1; },
2 => { current_value -= 1; },
3 => { current_value *= current_value; },
1 => {
current_value += 1;
},
2 => {
current_value -= 1;
},
3 => {
current_value *= current_value;
},
}
std.debug.print("{} ", .{current_value});

@ -29,16 +29,22 @@ pub fn main() void {
Ops.inc,
Ops.pow,
Ops.dec,
Ops.dec
Ops.dec,
};
var current_value: u32 = 0;
for (operations) |op| {
switch (op) {
Ops.inc => { current_value += 1; },
Ops.dec => { current_value -= 1; },
Ops.pow => { current_value *= current_value; },
Ops.inc => {
current_value += 1;
},
Ops.dec => {
current_value -= 1;
},
Ops.pow => {
current_value *= current_value;
},
// No "else" needed! Why is that?
}

@ -54,6 +54,6 @@ pub fn main() void {
std.debug.print("Your wizard has {} health and {} gold.", .{
glorp_the_wise.health,
glorp_the_wise.gold
glorp_the_wise.gold,
});
}

@ -45,7 +45,8 @@ pub fn main() void {
// Printing all RPG characters in a loop:
for (chars) |c, num| {
std.debug.print("Character {} - G:{} H:{} XP:{}\n",
.{num+1, c.gold, c.health, c.experience});
std.debug.print("Character {} - G:{} H:{} XP:{}\n", .{
num + 1, c.gold, c.health, c.experience,
});
}
}

@ -12,7 +12,6 @@ pub fn main() void {
makeFive(&num);
std.debug.print("num: {}, ", .{num});
// Now something interesting. Let's pass a reference to a
// specific array value:
makeFive(&more_nums[2]);

@ -44,7 +44,7 @@ const Class = enum{
const Character = struct {
class: Class,
gold: u32,
health: u8 = 100, // <--- You can also fields a default value!
health: u8 = 100, // <--- You can also provide fields a default value!
experience: u32,
};
@ -60,7 +60,6 @@ pub fn main() void {
printCharacter(???);
}
// Note how this function's "c" parameter is a pointer to a Character struct.
fn printCharacter(c: *Character) void {

@ -39,7 +39,6 @@ fn deepThought() ?u8 {
// But we'll leave this as-is. Sorry Deep Thought.
return null;
}
//
// Blast from the past:
//
// Optionals are a lot like error union types which can either

Loading…
Cancel
Save