From aa74dde367af48ee7ec4fa29b37c453936b57895 Mon Sep 17 00:00:00 2001 From: susubub Date: Wed, 17 Apr 2024 20:04:43 -0300 Subject: [PATCH 01/13] fixing little typo on exercise 107_files2.zig --- exercises/107_files2.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/107_files2.zig b/exercises/107_files2.zig index dadfdf6..3023d52 100644 --- a/exercises/107_files2.zig +++ b/exercises/107_files2.zig @@ -13,7 +13,7 @@ // - First, we open the {project_root}/output/ directory // - Secondly, we open file `zigling.txt` in that directory // - then, we initalize an array of character with all letter 'A', and print it -// - Afte that, we read the content of the file to the array +// - After that, we read the content of the file to the array // - Finally, we print out the read content const std = @import("std"); From c94eb33e4417aa1281d8f3c644ea7981112824d6 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Sat, 20 Apr 2024 22:35:14 +0200 Subject: [PATCH 02/13] Switch to new zig dev release 0.13 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2cd5778..d08dd2d 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Verify the installation and build number of `zig` like so: ``` $ zig version -0.12.0-dev.xxxx+xxxxxxxxx +0.13.0-dev.xxxx+xxxxxxxxx ``` Clone this repository with Git: @@ -74,8 +74,8 @@ the appropriate tag. The Zig language is under very active development. In order to be current, Ziglings tracks **development** builds of the Zig compiler rather than versioned **release** builds. The last -stable release was `0.11.0`, but Ziglings needs a dev build with -pre-release version "0.12.0" and a build number at least as high +stable release was `0.12.0`, but Ziglings needs a dev build with +pre-release version "0.13.0" and a build number at least as high as that shown in the example version check above. It is likely that you'll download a build which is _greater_ than From e7eaa080b649db483675aba8a40ae0d42028ac01 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Wed, 24 Apr 2024 14:20:57 +0000 Subject: [PATCH 03/13] Update .woodpecker/eowyn.yaml Add tag "latest" --- .woodpecker/eowyn.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.woodpecker/eowyn.yaml b/.woodpecker/eowyn.yaml index f6eceb0..4c04573 100644 --- a/.woodpecker/eowyn.yaml +++ b/.woodpecker/eowyn.yaml @@ -1,6 +1,6 @@ steps: - name: eowyn - image: ziglings/ziglang + image: ziglings/ziglang:latest commands: - sh ./patches/eowyn.sh when: From b484be9ac16576b0dd4cd25506bc95dd32a1da93 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Wed, 24 Apr 2024 14:40:01 +0000 Subject: [PATCH 04/13] Update .woodpecker/eowyn.yaml Add pull command --- .woodpecker/eowyn.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.woodpecker/eowyn.yaml b/.woodpecker/eowyn.yaml index 4c04573..913e943 100644 --- a/.woodpecker/eowyn.yaml +++ b/.woodpecker/eowyn.yaml @@ -1,6 +1,7 @@ steps: - name: eowyn image: ziglings/ziglang:latest + pull: true commands: - sh ./patches/eowyn.sh when: From 4dbd056100c8a7a965e189b2670264a331a544ff Mon Sep 17 00:00:00 2001 From: David Hain Date: Sat, 4 May 2024 18:51:00 +0200 Subject: [PATCH 05/13] fix: typo: % instead of @ for a builtin function --- exercises/094_c_math.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/094_c_math.zig b/exercises/094_c_math.zig index 61e2c7b..ec59a86 100644 --- a/exercises/094_c_math.zig +++ b/exercises/094_c_math.zig @@ -13,7 +13,7 @@ // How could we do that? A good method is to use the modulo function. // But if we write "765.2 % 360", it only works with float values // that are known at compile time. -// In Zig, we would use %mod(a, b) instead. +// In Zig, we would use @mod(a, b) instead. // // Let us now assume that we cannot do this in Zig, but only with // a C function from the standard library. In the library "math", From 5c2354a1bf028bb0caad68b4568bee72e4bacc3f Mon Sep 17 00:00:00 2001 From: David Hain Date: Sat, 4 May 2024 21:12:54 +0200 Subject: [PATCH 06/13] fix: typo: removed extra s --- exercises/098_bit_manipulation2.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/098_bit_manipulation2.zig b/exercises/098_bit_manipulation2.zig index 9abb14c..64cea4b 100644 --- a/exercises/098_bit_manipulation2.zig +++ b/exercises/098_bit_manipulation2.zig @@ -39,7 +39,7 @@ fn isPangram(str: []const u8) bool { // first we check if the string has at least 26 characters if (str.len < 26) return false; - // we uses a 32 bit variable of which we need 26 bits + // we use a 32 bit variable of which we need 26 bits var bits: u32 = 0; // loop about all characters in the string From c936c5e1232790ef8aa5a50ce37d42b57aee8781 Mon Sep 17 00:00:00 2001 From: David Hain Date: Sat, 4 May 2024 22:35:07 +0200 Subject: [PATCH 07/13] fix: many grammatical errors --- exercises/106_files.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/exercises/106_files.zig b/exercises/106_files.zig index aa58ee0..a6131ed 100644 --- a/exercises/106_files.zig +++ b/exercises/106_files.zig @@ -50,20 +50,20 @@ pub fn main() !void { // we try to open the file `zigling.txt`, // and propagate the error up if there are any errors const file: std.fs.File = try output_dir.createFile("zigling.txt", .{}); - // it is a good habit to close a file after you are done with - // so that other program can read it and prevent data corruption + // it is a good habit to close a file after you are done with it + // so that other programs can read it and prevent data corruption // but here we are not yet done writing to the file - // if only there are a keyword in zig that - // allow you "defer" code execute to the end of scope... + // if only there were a keyword in zig that + // allows you "defer" code execute to the end of scope... file.close(); - // !you are not allow to switch this two lines to before file closing line! + // !you are not allowed to switch these two lines above the file closing line! const byte_written = try file.write("It's zigling time!"); std.debug.print("Successfully wrote {d} bytes.\n", .{byte_written}); } // to check if you actually write to the file, you can either, // 1. open the file on your text editor, or -// 2. print the content of the file in the console with command +// 2. print the content of the file in the console with the following command // >> cat ./output/zigling.txt // // @@ -89,4 +89,4 @@ pub fn main() !void { // - go to documentation of the struct `std.fs.Dir` here // https://ziglang.org/documentation/master/std/#std.fs.Dir // - can you find a function for opening a file? how about deleting a file? -// - what kind of option can you uses with those function? +// - what kind of options can you use with those functions? From 8cb2a5aa3c870fe398ef0b02b9b53c8d90256672 Mon Sep 17 00:00:00 2001 From: David Hain Date: Sat, 4 May 2024 22:53:04 +0200 Subject: [PATCH 08/13] fix: some grammatical errors --- exercises/107_files2.zig | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exercises/107_files2.zig b/exercises/107_files2.zig index 3023d52..9266358 100644 --- a/exercises/107_files2.zig +++ b/exercises/107_files2.zig @@ -5,14 +5,14 @@ // with content `It's zigling time!`(18 byte total) // // Now there no point in writing to a file if we don't read from it am I right? -// let's wrote a program to read the content of the file that we just created. +// let's write a program to read the content of the file that we just created. // -// I am assuming you've created the appropriate files for this to work. +// I am assuming that you've created the appropriate files for this to work. // // Alright, bud, lean in close here's the game plan. // - First, we open the {project_root}/output/ directory // - Secondly, we open file `zigling.txt` in that directory -// - then, we initalize an array of character with all letter 'A', and print it +// - then, we initalize an array of characters with all letter 'A', and print it // - After that, we read the content of the file to the array // - Finally, we print out the read content @@ -31,22 +31,22 @@ pub fn main() !void { defer file.close(); // initalize an array of u8 with all letter 'A'. - // we need to pick a size of the array, 64 seems like a good number. + // we need to pick the size of the array, 64 seems like a good number. // fix the initalization below var content = ['A']*64; // this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA` std.debug.print("{s}\n", .{content}); - // okay, seem like threat of violence is not the answer in this case + // okay, seems like a threat of violence is not the answer in this case // can you go here to find a way to read the content ? // https://ziglang.org/documentation/master/std/#std.fs.File - // hint: you might find two answer that are both vaild in this case - const byte_read = zig_read_the_file_or_i_will_fight_you(&content); + // hint: you might find two answers that are both vaild in this case + const bytes_read = zig_read_the_file_or_i_will_fight_you(&content); // Woah, too screamy, I know you're excited for zigling time but tone it down a bit // Can you print only what we read from the file ? - std.debug.print("Successfully Read {d} byte: {s}\n", .{ - byte_read, + std.debug.print("Successfully Read {d} bytes: {s}\n", .{ + bytes_read, content, // change this line only }); } From 165cc199ca4d88fbc58c2662d8e588cba597b19d Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Sun, 5 May 2024 01:16:23 +0200 Subject: [PATCH 09/13] Fix patches for 106 and 107 --- build.zig | 2 +- patches/patches/106_files.patch | 10 +++++----- patches/patches/107_files2.patch | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build.zig b/build.zig index 7620db0..b03e389 100644 --- a/build.zig +++ b/build.zig @@ -1128,7 +1128,7 @@ const exercises = [_]Exercise{ .main_file = "107_files2.zig", .output = \\AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - \\Successfully Read 18 byte: It's zigling time! + \\Successfully Read 18 bytes: It's zigling time! , }, .{ diff --git a/patches/patches/106_files.patch b/patches/patches/106_files.patch index 7927cee..e2bdbca 100644 --- a/patches/patches/106_files.patch +++ b/patches/patches/106_files.patch @@ -1,5 +1,5 @@ ---- exercises/106_files.zig 2024-03-27 16:52:05.660910200 +0800 -+++ answers/106_files.zig 2024-03-27 16:52:09.649422200 +0800 +--- exercises/106_files.zig 2024-05-05 00:48:25.808548611 +0200 ++++ answers/106_files.zig 2024-05-05 01:00:40.742969819 +0200 @@ -35,7 +35,7 @@ // by doing nothing // @@ -20,10 +20,10 @@ // we try to open the file `zigling.txt`, @@ -55,7 +55,7 @@ // but here we are not yet done writing to the file - // if only there are a keyword in zig that - // allow you "defer" code execute to the end of scope... + // if only there were a keyword in zig that + // allows you "defer" code execute to the end of scope... - file.close(); + defer file.close(); - // !you are not allow to switch this two lines to before file closing line! + // !you are not allowed to switch these two lines above the file closing line! const byte_written = try file.write("It's zigling time!"); diff --git a/patches/patches/107_files2.patch b/patches/patches/107_files2.patch index 57e04e7..d434b52 100644 --- a/patches/patches/107_files2.patch +++ b/patches/patches/107_files2.patch @@ -1,8 +1,8 @@ ---- exercises/107_files2.zig 2024-03-27 16:51:56.199719600 +0800 -+++ answers/107_files2.zig 2024-03-27 16:52:01.650935300 +0800 +--- exercises/107_files2.zig 2024-05-05 00:48:25.808548611 +0200 ++++ answers/107_files2.zig 2024-05-05 01:14:03.866062288 +0200 @@ -33,7 +33,7 @@ // initalize an array of u8 with all letter 'A'. - // we need to pick a size of the array, 64 seems like a good number. + // we need to pick the size of the array, 64 seems like a good number. // fix the initalization below - var content = ['A']*64; + var content = [_]u8{'A'} ** 64; @@ -12,15 +12,15 @@ @@ -41,12 +41,12 @@ // can you go here to find a way to read the content ? // https://ziglang.org/documentation/master/std/#std.fs.File - // hint: you might find two answer that are both vaild in this case -- const byte_read = zig_read_the_file_or_i_will_fight_you(&content); -+ const byte_read = try file.read(&content); + // hint: you might find two answers that are both vaild in this case +- const bytes_read = zig_read_the_file_or_i_will_fight_you(&content); ++ const bytes_read = try file.read(&content); // Woah, too screamy, I know you're excited for zigling time but tone it down a bit // Can you print only what we read from the file ? - std.debug.print("Successfully Read {d} byte: {s}\n", .{ - byte_read, + std.debug.print("Successfully Read {d} bytes: {s}\n", .{ + bytes_read, - content, // change this line only -+ content[0..byte_read], // change this line only ++ content[0..bytes_read], // change this line only }); } From 19bd8745e4c3effb016fb0c12ab9fddef6fe607d Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Mon, 6 May 2024 09:13:56 +0200 Subject: [PATCH 10/13] Fix some typos --- exercises/096_memory_allocation.zig | 6 +++--- exercises/097_bit_manipulation.zig | 10 +++++----- exercises/098_bit_manipulation2.zig | 8 ++++---- exercises/099_formatting.zig | 8 ++++---- exercises/104_threading.zig | 4 ++-- exercises/105_threading2.zig | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/exercises/096_memory_allocation.zig b/exercises/096_memory_allocation.zig index 1ece922..58de7b0 100644 --- a/exercises/096_memory_allocation.zig +++ b/exercises/096_memory_allocation.zig @@ -30,9 +30,9 @@ // std.debug.print("slice_ptr={*}\n", .{slice_ptr}); // } -// Instead of a simple integer or a constant sized slice, this -// program requires a slice to be allocated that is the same size as -// an input array. +// Instead of a simple integer or a slice with a constant size, +// this program requires allocating a slice that is the same size +// as an input array. // Given a series of numbers, take the running average. In other // words, each item N should contain the average of the last N diff --git a/exercises/097_bit_manipulation.zig b/exercises/097_bit_manipulation.zig index 424fb4c..03fc72d 100644 --- a/exercises/097_bit_manipulation.zig +++ b/exercises/097_bit_manipulation.zig @@ -1,5 +1,5 @@ // -// Bit manipulations is a very powerful tool just also from Zig. +// Bit manipulation is a very powerful tool, also from Zig. // Since the dawn of the computer age, numerous algorithms have been // developed that solve tasks solely by moving, setting, or logically // combining bits. @@ -8,10 +8,10 @@ // functions where possible. And it is often possible with calculations // based on integers. // -// Often it is not easy to understand at first glance what exactly these +// At first glance, it is often not easy to understand what exactly these // algorithms do when only "numbers" in memory areas change outwardly. -// But it must never be forgotten that the numbers only represent the -// interpretation of the bit sequences. +// However, it should never be forgotten that the numbers only represent +// the interpretation of the bit sequences. // // Quasi the reversed case we have otherwise, namely that we represent // numbers in bit sequences. @@ -21,7 +21,7 @@ // Zig provides all the necessary functions to change the bits inside // a variable. It is distinguished whether the bit change leads to an // overflow or not. The details are in the Zig documentation in section -// 10.1 "Table of Operators". +// "Table of Operators". // // Here are some examples of how the bits of variables can be changed: // diff --git a/exercises/098_bit_manipulation2.zig b/exercises/098_bit_manipulation2.zig index 64cea4b..979b103 100644 --- a/exercises/098_bit_manipulation2.zig +++ b/exercises/098_bit_manipulation2.zig @@ -1,5 +1,5 @@ // -// Another useful practice for bit manipulation is setting bits as flags. +// Another useful application for bit manipulation is setting bits as flags. // This is especially useful when processing lists of something and storing // the states of the entries, e.g. a list of numbers and for each prime // number a flag is set. @@ -19,9 +19,9 @@ // For example, you could take an array of bool and set the value to 'true' // for each letter in the order of the alphabet (a=0; b=1; etc.) found in // the sentence. However, this is neither memory efficient nor particularly -// fast. Instead we take a simpler way, very similar in principle, we define -// a variable with at least 26 bits (e.g. u32) and also set the bit for each -// letter found at the corresponding position. +// fast. Instead we choose a simpler approach that is very similar in principle: +// We define a variable with at least 26 bits (e.g. u32) and set the bit for +// each letter that is found in the corresponding position. // // Zig provides functions for this in the standard library, but we prefer to // solve it without these extras, after all we want to learn something. diff --git a/exercises/099_formatting.zig b/exercises/099_formatting.zig index 07af3ba..1952c5e 100644 --- a/exercises/099_formatting.zig +++ b/exercises/099_formatting.zig @@ -19,10 +19,10 @@ // https://github.com/ziglang/zig/blob/master/lib/std/fmt.zig#L29 // // Zig already has a very nice selection of formatting options. -// These can be used in different ways, but typically to convert -// numerical values into various text representations. The -// results can be used for direct output to a terminal or stored -// for later use or written to a file. The latter is useful when +// These can be used in different ways, but generally to convert +// numerical values into various text representations. The results +// can be used for direct output to a terminal or stored for +// later use or written to a file. The latter is useful when // large amounts of data are to be processed by other programs. // // In Ziglings, we are concerned with the output to the console. diff --git a/exercises/104_threading.zig b/exercises/104_threading.zig index ac40b3c..9c4e216 100644 --- a/exercises/104_threading.zig +++ b/exercises/104_threading.zig @@ -4,8 +4,8 @@ // one possibility, namely asynchronous processes, in Exercises 84-91. // // However, the computing power of the processor is only distributed to -// the started tasks, which always reaches its limits when pure computing -// power is called up. +// the started and running tasks, which always reaches its limits when +// pure computing power is called up. // // For example, in blockchains based on proof of work, the miners have // to find a nonce for a certain character string so that the first m bits diff --git a/exercises/105_threading2.zig b/exercises/105_threading2.zig index c85f801..94a2c71 100644 --- a/exercises/105_threading2.zig +++ b/exercises/105_threading2.zig @@ -1,6 +1,6 @@ // -// Now that we are familiar with the principles of multi threading, we -// boldly venture into a practical example from mathematics. +// Now that we are familiar with the principles of multi-threading, +// let's boldly venture into a practical example from mathematics. // We will determine the circle number PI with sufficient accuracy. // // There are different methods for this, and some of them are several From 5da194ba9c2b3c53524ad8cf5bbe152a448b9885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20A=CC=81quila?= Date: Mon, 6 May 2024 07:47:27 -0300 Subject: [PATCH 11/13] Add devcontainer.json --- .devcontainer/devcontainer.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..beea353 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,31 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/debian +{ + "name": "Ziglings", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:bullseye", + "features": { + "ghcr.io/devcontainers-contrib/features/zig:1": { + "version": "master" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ziglang.vscode-zig" + ] + } + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} From 67f87a76c23d6205370b0620f82d5847f8a76688 Mon Sep 17 00:00:00 2001 From: Chris Boesch Date: Fri, 10 May 2024 23:21:04 +0200 Subject: [PATCH 12/13] Nobody wants the long version of finding out if a variable is set. So switched to the short version with 'orelse'. ;) --- exercises/046_optionals2.zig | 4 +--- patches/patches/046_optionals2.patch | 13 ++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/exercises/046_optionals2.zig b/exercises/046_optionals2.zig index d3f65bb..e745d29 100644 --- a/exercises/046_optionals2.zig +++ b/exercises/046_optionals2.zig @@ -51,8 +51,6 @@ fn visitElephants(first_elephant: *Elephant) void { // We should stop once we encounter a tail that // does NOT point to another element. What can // we put here to make that happen? - if (e.tail == null) ???; - - e = e.tail.?; + e = e.tail ??? } } diff --git a/patches/patches/046_optionals2.patch b/patches/patches/046_optionals2.patch index 66912eb..164c0d6 100644 --- a/patches/patches/046_optionals2.patch +++ b/patches/patches/046_optionals2.patch @@ -1,5 +1,5 @@ ---- exercises/046_optionals2.zig 2023-10-03 22:15:22.122241138 +0200 -+++ answers/046_optionals2.zig 2023-10-05 20:04:07.049433424 +0200 +--- exercises/046_optionals2.zig 2024-05-10 23:11:25.796632478 +0200 ++++ answers/046_optionals2.zig 2024-05-10 23:10:16.115335668 +0200 @@ -21,7 +21,7 @@ const Elephant = struct { @@ -9,12 +9,11 @@ visited: bool = false, }; -@@ -51,7 +51,7 @@ +@@ -51,6 +51,6 @@ // We should stop once we encounter a tail that // does NOT point to another element. What can // we put here to make that happen? -- if (e.tail == null) ???; -+ if (e.tail == null) break; - - e = e.tail.?; +- e = e.tail ??? ++ e = e.tail orelse break; } + } From efe2d19c694b5e10abddc29b1743da4b309fffb5 Mon Sep 17 00:00:00 2001 From: rpm0372 Date: Sat, 11 May 2024 22:38:15 +0000 Subject: [PATCH 13/13] Update exercises/105_threading2.zig The last word, '"diggits" was misspelled. --- exercises/105_threading2.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/105_threading2.zig b/exercises/105_threading2.zig index 94a2c71..7ca8f5c 100644 --- a/exercises/105_threading2.zig +++ b/exercises/105_threading2.zig @@ -104,4 +104,4 @@ fn thread_pi(pi: *f64, begin: u64, end: u64) !void { // to such an extent that seconds become minutes during execution. // // And you should remove the formatting restriction in "print", -// otherwise you will not be able to see the additional diggits. +// otherwise you will not be able to see the additional digits.