2021-01-04 18:40:34 -05:00
|
|
|
//
|
|
|
|
// Zig has some fun array operators.
|
|
|
|
//
|
|
|
|
// You can use '++' to concatenate two arrays:
|
2021-02-07 11:06:51 -05:00
|
|
|
//
|
2021-01-04 18:40:34 -05:00
|
|
|
// const a = [_]u8{ 1,2 };
|
|
|
|
// const b = [_]u8{ 3,4 };
|
2021-02-07 11:06:51 -05:00
|
|
|
// const c = a ++ b ++ [_]u8{ 5 }; // equals 1 2 3 4 5
|
2021-01-04 18:40:34 -05:00
|
|
|
//
|
|
|
|
// You can use '**' to repeat an array:
|
2021-02-07 11:06:51 -05:00
|
|
|
//
|
|
|
|
// const d = [_]u8{ 1,2,3 } ** 2; // equals 1 2 3 1 2 3
|
2021-01-04 18:40:34 -05:00
|
|
|
//
|
2022-03-19 19:46:29 -04:00
|
|
|
// Note that both '++' and '**' only operate on arrays while your
|
|
|
|
// program is _being compiled_. This special time is known in Zig
|
|
|
|
// parlance as "comptime" and we'll learn plenty more about that
|
|
|
|
// later.
|
|
|
|
//
|
2021-01-04 18:40:34 -05:00
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
pub fn main() void {
|
|
|
|
const le = [_]u8{ 1, 3 };
|
|
|
|
const et = [_]u8{ 3, 7 };
|
|
|
|
|
2021-02-07 11:06:51 -05:00
|
|
|
// (Problem 1)
|
|
|
|
// Please set this array concatenating the two arrays above.
|
|
|
|
// It should result in: 1 3 3 7
|
2021-01-04 18:40:34 -05:00
|
|
|
const leet = ???;
|
|
|
|
|
2021-02-07 11:06:51 -05:00
|
|
|
// (Problem 2)
|
2021-03-18 18:46:44 -04:00
|
|
|
// Please set this array using repetition.
|
2021-02-07 11:06:51 -05:00
|
|
|
// It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
|
2021-01-04 18:40:34 -05:00
|
|
|
const bit_pattern = [_]u8{ ??? } ** 3;
|
|
|
|
|
2021-02-07 11:06:51 -05:00
|
|
|
// Okay, that's all of the problems. Let's see the results.
|
|
|
|
//
|
2021-01-04 18:40:34 -05:00
|
|
|
// We could print these arrays with leet[0], leet[1],...but let's
|
2021-04-17 15:56:30 -04:00
|
|
|
// have a little preview of Zig 'for' loops instead:
|
|
|
|
//
|
|
|
|
// for (<item array>) |item| { <do something with item> }
|
2021-11-05 11:44:29 -04:00
|
|
|
//
|
2021-04-17 15:56:30 -04:00
|
|
|
// Don't worry, we'll cover looping properly in upcoming
|
|
|
|
// lessons.
|
|
|
|
//
|
2021-01-04 18:40:34 -05:00
|
|
|
std.debug.print("LEET: ", .{});
|
|
|
|
|
2021-04-17 15:56:30 -04:00
|
|
|
for (leet) |n| {
|
|
|
|
std.debug.print("{}", .{n});
|
2021-01-04 18:40:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std.debug.print(", Bits: ", .{});
|
|
|
|
|
2021-04-17 15:56:30 -04:00
|
|
|
for (bit_pattern) |n| {
|
|
|
|
std.debug.print("{}", .{n});
|
2021-01-04 18:40:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std.debug.print("\n", .{});
|
|
|
|
}
|