Compare commits

..

No commits in common. "fc818d088d96997f2f6d70484bb3bcaf19b3fead" and "dfdaf03d9902058b97713428b628a7a36c9fdf52" have entirely different histories.

14 changed files with 27 additions and 27 deletions

View File

@ -16,6 +16,6 @@
//
const std = @import("std");
pub fn main() void {
fn main() void {
std.debug.print("Hello world!\n", .{});
}

View File

@ -11,7 +11,7 @@
// Please complete the import below:
//
const std = @import("std");
??? = @import("std");
pub fn main() void {
std.debug.print("Standard Library.\n", .{});

View File

@ -34,12 +34,12 @@
const std = @import("std");
pub fn main() void {
var n: u8 = 50;
const n: u8 = 50;
n = n + 5;
const pi: u32 = 314159;
const pi: u8 = 314159;
const negative_eleven: i8 = -11;
const negative_eleven: u8 = -11;
// There are no errors in the next line, just explanation:
// Perhaps you noticed before that the print function takes two

View File

@ -27,7 +27,7 @@ pub fn main() void {
// (Problem 1)
// This "const" is going to cause a problem later - can you see what it is?
// How do we fix it?
var some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
const some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
// Individual values can be set with '[]' notation.
// Example: This line changes the first prime to 2 (which is correct):
@ -40,11 +40,11 @@ pub fn main() void {
// (Problem 2)
// Looks like we need to complete this expression. Use the example
// above to set "fourth" to the fourth element of the some_primes array:
const fourth = some_primes[3];
const fourth = some_primes[???];
// (Problem 3)
// Use the len property to get the length of the array:
const length = some_primes.len;
const length = some_primes.???;
std.debug.print("First: {}, Fourth: {}, Length: {}\n", .{
first, fourth, length,

View File

@ -25,12 +25,12 @@ pub fn main() void {
// (Problem 1)
// Please set this array concatenating the two arrays above.
// It should result in: 1 3 3 7
const leet = le ++ et;
const leet = ???;
// (Problem 2)
// Please set this array using repetition.
// It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3;
const bit_pattern = [_]u8{ ??? } ** 3;
// Okay, that's all of the problems. Let's see the results.
//

View File

@ -24,18 +24,18 @@ pub fn main() void {
// (Problem 1)
// Use array square bracket syntax to get the letter 'd' from
// the string "stardust" above.
const d: u8 = ziggy[4];
const d: u8 = ziggy[???];
// (Problem 2)
// Use the array repeat '**' operator to make "ha ha ha ".
const laugh = "ha " ** 3;
const laugh = "ha " ???;
// (Problem 3)
// Use the array concatenation '++' operator to make "Major Tom".
// (You'll need to add a space as well!)
const major = "Major";
const tom = "Tom";
const major_tom = major ++ " " ++ tom;
const major_tom = major ??? tom;
// That's all the problems. Let's see our results:
std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });

View File

@ -15,9 +15,9 @@ const std = @import("std");
pub fn main() void {
const lyrics =
\\Ziggy played guitar
\\Jamming good with Andrew Kelley
\\And the Spiders from Mars
Ziggy played guitar
Jamming good with Andrew Kelley
And the Spiders from Mars
;
std.debug.print("{s}\n", .{lyrics});

View File

@ -19,7 +19,7 @@ pub fn main() void {
// the idiomatic type to use for array indexing.
//
// There IS a problem on this line, but 'usize' isn't it.
var x: usize = 1;
const x: usize = 1;
// Note: When you want to declare memory (an array in this
// case) without putting anything in it, you can set it to
@ -33,10 +33,10 @@ pub fn main() void {
lang[0] = letters[x];
x = 3;
lang[1] = letters[x];
lang[???] = letters[x];
x = 5;
lang[2] = letters[x];
x = ???;
lang[2] = letters[???];
// We want to "Program in Zig!" of course:
std.debug.print("Program in {s}!\n", .{lang});

View File

@ -24,7 +24,7 @@ pub fn main() void {
const foo = 1;
// Please fix this condition:
if (foo == 1) {
if (foo) {
// We want our program to print this message!
std.debug.print("Foo is 1!\n", .{});
} else {

View File

@ -10,7 +10,7 @@ pub fn main() void {
// Please use an if...else expression to set "price".
// If discount is true, the price should be $17, otherwise $20:
const price: u8 = if (discount) 17 else 20;
const price: u8 = if ???;
std.debug.print("With the discount, the price is ${}.\n", .{price});
}

View File

@ -21,7 +21,7 @@ pub fn main() void {
var n: u32 = 2;
// Please use a condition that is true UNTIL "n" reaches 1024:
while (n < 1024) {
while (???) {
// Print the current number
std.debug.print("{} ", .{n});

View File

@ -25,7 +25,7 @@ pub fn main() void {
// Please set the continue expression so that we get the desired
// results in the print statement below.
while (n < 1000) : (n *= 2) {
while (n < 1000) : ??? {
// Print the current number
std.debug.print("{} ", .{n});
}

View File

@ -24,8 +24,8 @@ pub fn main() void {
while (n <= 20) : (n += 1) {
// The '%' symbol is the "modulo" operator and it
// returns the remainder after division.
if (n % 3 == 0) continue;
if (n % 5 == 0) continue;
if (n % 3 == 0) ???;
if (n % 5 == 0) ???;
std.debug.print("{} ", .{n});
}

View File

@ -18,7 +18,7 @@ pub fn main() void {
// Oh dear! This while loop will go forever?!
// Please fix this so the print statement below gives the desired output.
while (true) : (n += 1) {
if (n == 4) break;
if (???) ???;
}
// Result: we want n=4