Finished quiz 3
This commit is contained in:
parent
c245fd663a
commit
af15995fc7
@ -25,6 +25,6 @@ pub fn main() void {
|
||||
// We're just missing a couple things. One thing we're NOT missing is the
|
||||
// keyword "pub", which is not needed here. Can you guess why?
|
||||
//
|
||||
??? deepThought() ??? {
|
||||
fn deepThought() u8 {
|
||||
return 42; // Number courtesy Douglas Adams
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ pub fn main() void {
|
||||
// You'll need to figure out the parameter name and type that we're
|
||||
// expecting. The output type has already been specified for you.
|
||||
//
|
||||
fn twoToThe(???) u32 {
|
||||
fn twoToThe(my_number: u32) u32 {
|
||||
return std.math.pow(u32, 2, my_number);
|
||||
// std.math.pow(type, a, b) takes a numeric type and two
|
||||
// numbers of that type (or that can coerce to that type) and
|
||||
|
||||
@ -21,8 +21,8 @@ pub fn main() void {
|
||||
//
|
||||
// This function prints, but does not return anything.
|
||||
//
|
||||
fn printPowersOfTwo(numbers: [4]u16) ??? {
|
||||
loop (numbers) |n| {
|
||||
fn printPowersOfTwo(numbers: [4]u16) void {
|
||||
for (numbers) |n| {
|
||||
std.debug.print("{} ", .{twoToThe(n)});
|
||||
}
|
||||
}
|
||||
@ -31,13 +31,13 @@ fn printPowersOfTwo(numbers: [4]u16) ??? {
|
||||
// exercise. But don't be fooled! This one does the math without the aid
|
||||
// of the standard library!
|
||||
//
|
||||
fn twoToThe(number: u16) ??? {
|
||||
fn twoToThe(number: u16) u16 {
|
||||
var n: u16 = 0;
|
||||
var total: u16 = 1;
|
||||
|
||||
loop (n < number) : (n += 1) {
|
||||
while (n < number) : (n += 1) {
|
||||
total *= 2;
|
||||
}
|
||||
|
||||
return ???;
|
||||
return total;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user