mirror of
https://codeberg.org/ziglings/exercises.git
synced 2026-06-08 07:50:00 +00:00
fixed removed array multiplication
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
--- exercises/005_arrays2.zig 2023-10-03 22:15:22.122241138 +0200
|
||||
+++ answers/005_arrays2.zig 2023-10-05 20:04:06.862763262 +0200
|
||||
@@ -25,12 +25,12 @@
|
||||
--- exercises/005_arrays2.zig 2026-05-04 16:26:32.778330847 +0200
|
||||
+++ answers/005_arrays2.zig 2026-05-04 16:26:13.082917974 +0200
|
||||
@@ -21,12 +21,12 @@
|
||||
// (Problem 1)
|
||||
// Please set this array concatenating the two arrays above.
|
||||
// It should result in: 1 3 3 7
|
||||
@@ -10,8 +10,8 @@
|
||||
// (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{ ??? } ** 3;
|
||||
+ const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3;
|
||||
- const bit_pattern_unit = [_]u8{ ??? };
|
||||
+ const bit_pattern_unit = [_]u8{ 1, 0, 0, 1 };
|
||||
const bit_pattern: [3 * bit_pattern_unit.len]u8 = @bitCast(@as([3][bit_pattern_unit.len]u8, @splat(bit_pattern_unit)));
|
||||
|
||||
// Okay, that's all of the problems. Let's see the results.
|
||||
//
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
--- exercises/006_strings.zig 2023-10-03 22:15:22.122241138 +0200
|
||||
+++ answers/006_strings.zig 2023-10-05 20:04:06.869430053 +0200
|
||||
@@ -24,18 +24,18 @@
|
||||
--- exercises/006_strings.zig 2026-05-04 17:04:31.763821070 +0200
|
||||
+++ answers/006_strings.zig 2026-05-04 17:02:11.672866263 +0200
|
||||
@@ -24,14 +24,14 @@
|
||||
// (Problem 1)
|
||||
// Use array square bracket syntax to get the letter 'd' from
|
||||
// the string "stardust" above.
|
||||
@@ -8,11 +8,6 @@
|
||||
+ const d: u8 = ziggy[4];
|
||||
|
||||
// (Problem 2)
|
||||
// Use the array repeat '**' operator to make "ha ha ha ".
|
||||
- const laugh = "ha " ???;
|
||||
+ const laugh = "ha " ** 3;
|
||||
|
||||
// (Problem 3)
|
||||
// Use the array concatenation '++' operator to make "Major Tom".
|
||||
// (You'll need to add a space as well!)
|
||||
const major = "Major";
|
||||
@@ -21,4 +16,4 @@
|
||||
+ 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 });
|
||||
std.debug.print("d={u} {s}\n", .{ d, major_tom });
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- exercises/058_quiz7.zig 2024-10-28 09:06:49.448505460 +0100
|
||||
+++ answers/058_quiz7.zig 2024-10-28 09:35:14.631932322 +0100
|
||||
--- exercises/058_quiz7.zig 2026-05-04 16:34:31.692458399 +0200
|
||||
+++ answers/058_quiz7.zig 2026-05-04 16:34:29.239406323 +0200
|
||||
@@ -192,8 +192,8 @@
|
||||
// Oops! The hermit forgot how to capture the union values
|
||||
// in a switch statement. Please capture each value as
|
||||
@@ -11,7 +11,7 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -255,7 +255,7 @@
|
||||
@@ -254,7 +254,7 @@
|
||||
// dereference and optional value "unwrapping" look
|
||||
// together. Remember that you return the address with the
|
||||
// "&" operator.
|
||||
@@ -20,7 +20,7 @@
|
||||
// Try to make your answer this long:__________;
|
||||
}
|
||||
return null;
|
||||
@@ -309,7 +309,7 @@
|
||||
@@ -308,7 +308,7 @@
|
||||
//
|
||||
// Looks like the hermit forgot something in the return value of
|
||||
// this function. What could that be?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- exercises/067_comptime2.zig 2025-12-07 22:51:24.396031248 +0100
|
||||
+++ answers/067_comptime2.zig 2025-12-07 22:50:18.721616293 +0100
|
||||
--- exercises/067_comptime2.zig 2026-05-04 15:38:52.565144012 +0200
|
||||
+++ answers/067_comptime2.zig 2026-05-04 15:37:20.257213463 +0200
|
||||
@@ -36,7 +36,7 @@
|
||||
// In this contrived example, we've decided to allocate some
|
||||
// arrays using a variable count! But something's missing...
|
||||
@@ -8,4 +8,4 @@
|
||||
+ comptime var count = 0;
|
||||
|
||||
count += 1;
|
||||
const a1: [count]u8 = .{'A'} ** count;
|
||||
const a1: [count]u8 = @splat('A');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- exercises/074_comptime9.zig 2026-04-30 19:28:08.990995153 +0200
|
||||
+++ answers/074_comptime9.zig 2026-04-30 19:27:09.642728692 +0200
|
||||
--- exercises/074_comptime9.zig 2026-05-04 17:11:05.144118157 +0200
|
||||
+++ answers/074_comptime9.zig 2026-05-04 17:10:36.778519877 +0200
|
||||
@@ -28,12 +28,12 @@
|
||||
start, // Ready to start a new animal.
|
||||
l, // This means we've seen an "l", so if we see an "m", we know it's a Llama.
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
// We return an array of animals representing the creature. (This is why we
|
||||
// really needed the 'count' parameter. Arrays need a size.)
|
||||
var animals: [count]Animal = .{undefined} ** count;
|
||||
var animals: [count]Animal = undefined;
|
||||
- var next_animal: usize = 0;
|
||||
+ comptime var next_animal: usize = 0;
|
||||
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
--- exercises/075_quiz8.zig 2023-11-21 14:48:15.440702720 +0100
|
||||
+++ answers/075_quiz8.zig 2023-11-21 14:50:23.453311616 +0100
|
||||
@@ -49,7 +49,11 @@
|
||||
--- exercises/075_quiz8.zig 2026-05-04 15:51:48.254371574 +0200
|
||||
+++ answers/075_quiz8.zig 2026-05-04 15:49:28.426445382 +0200
|
||||
@@ -48,7 +48,13 @@
|
||||
// instead.
|
||||
//
|
||||
// Please fill in the body of this function!
|
||||
fn makePath(from: *Place, to: *Place, dist: u8) Path {
|
||||
-
|
||||
-fn makePath(from: *Place, to: *Place, dist: u8) Path {}
|
||||
+fn makePath(from: *Place, to: *Place, dist: u8) Path {
|
||||
+ return Path{
|
||||
+ .from = from,
|
||||
+ .to = to,
|
||||
+ .dist = dist,
|
||||
+ };
|
||||
}
|
||||
+}
|
||||
|
||||
// Using our new function, these path definitions take up considerably less
|
||||
// space in our program now!
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
--- exercises/110_files2.zig 2026-03-20 19:23:48.874150121 +0100
|
||||
+++ answers/110_files2.zig 2026-04-02 10:51:15.815831734 +0200
|
||||
--- exercises/110_files2.zig 2026-05-04 17:08:38.913033915 +0200
|
||||
+++ answers/110_files2.zig 2026-05-04 17:08:37.112995948 +0200
|
||||
@@ -39,7 +39,7 @@
|
||||
// initialize an array of u8 with all letter 'A'
|
||||
// we need to pick the size of the array, 64 seems like a good number
|
||||
// fix the initialization below
|
||||
- var content = ['A']*64;
|
||||
+ var content = [_]u8{'A'} ** 64;
|
||||
+ var content: [64]u8 = @splat('A');
|
||||
// this should print out : `AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA`
|
||||
std.debug.print("{s}\n", .{content});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user