Skip to content

Commit 7491e3d

Browse files
author
Chris Boesch
committed
changed the patch files that we can also use them with busybox for testing in Woodpecker
1 parent 992323a commit 7491e3d

File tree

109 files changed

+1606
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1606
-770
lines changed

patches/eowyn.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ then
2222
fi
2323

2424
# Which version we have?
25-
echo "I am in version 23.4.25.1, let's try our magic power."
25+
echo "Zig version" $(zig version)
26+
echo "Eowyn version 23.10.5.1, let's try our magic power."
27+
echo ""
2628

2729
# Create directory of healing if it doesn't already exist.
2830
mkdir -p patches/healed
@@ -39,7 +41,9 @@ do
3941
# Apply the bandages to the wounds, grow new limbs, let
4042
# new life spring into the broken bodies of the fallen.
4143
echo Healing "$true_name"...
42-
./test/patch --output="patches/healed/$true_name.zig" "$broken" "$patch_name"
44+
cp "$broken" "patches/healed/$true_name.zig"
45+
patch -i "$patch_name" "patches/healed/$true_name.zig"
46+
4347
else
4448
echo Cannot heal "$true_name". No patch found.
4549
fi

patches/frodo.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
#
3+
# "How do you pick up the threads of an old life?
4+
# How do you go on, when in your heart you begin
5+
# to understand... there is no going back?
6+
# There are some things that time cannot mend.
7+
# Some hurts that go too deep, that have taken hold."
8+
# Frodo, The Return of the King
9+
#
10+
#
11+
# This script shall repair the patches for the little
12+
# broken programs using the old patches in this directory
13+
# first, to heal them and then create new and better
14+
# patches, with Gollum's help.
15+
#
16+
set -e
17+
18+
# We check ourselves before we wreck ourselves.
19+
if [ ! -f patches/frodo.sh ]
20+
then
21+
echo "But I must be run from the project root directory."
22+
exit 1
23+
fi
24+
25+
# Create directory of answers if it doesn't already exist.
26+
mkdir -p answers
27+
28+
# Cycle through all the little broken Zig applications.
29+
i=0
30+
for broken in exercises/*.zig
31+
do
32+
((i=i+1))
33+
34+
# Remove the dir and extension, rendering the True Name.
35+
true_name=$(basename "$broken" .zig)
36+
patch_name="patches/patches/$true_name.patch"
37+
healed_name="answers/$true_name.zig"
38+
cp "$broken" "$healed_name"
39+
# echo "$patch_name"
40+
41+
if [ -f "$patch_name" ]
42+
then
43+
# Apply the bandages to the wounds, grow new limbs, let
44+
# new life spring into the broken bodies of the fallen.
45+
echo Healing "$true_name"...
46+
patch -i "$patch_name" "$healed_name"
47+
48+
# Create new prescriptions...
49+
echo Repairing "$patch_name"...
50+
if [ "$true_name.patch" = "999_the_end.patch" ]
51+
then
52+
i=999
53+
fi
54+
# with gollum's help!
55+
./patches/gollum.sh $i
56+
else
57+
echo Cannot repair "$true_name". No patch found.
58+
fi
59+
done
60+

patches/gollum.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ echo "Hissss! before: '$b'"
2626
echo " after: '$a'"
2727
echo " patch: '$p'"
2828

29-
diff $b $a > $p
29+
diff -u $b $a > $p
3030

3131
cat $p

patches/patches/001_hello.patch

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
19c19
2-
< fn main() void {
3-
---
4-
> pub fn main() void {
1+
--- exercises/001_hello.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/001_hello.zig 2023-10-05 20:04:06.846096282 +0200
3+
@@ -16,6 +16,6 @@
4+
//
5+
const std = @import("std");
6+
7+
-fn main() void {
8+
+pub fn main() void {
9+
std.debug.print("Hello world!\n", .{});
10+
}

patches/patches/002_std.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
14c14
2-
< ??? = @import("std");
3-
---
4-
> const std = @import("std");
1+
--- exercises/002_std.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/002_std.zig 2023-10-05 20:04:06.849429678 +0200
3+
@@ -11,7 +11,7 @@
4+
// Please complete the import below:
5+
//
6+
7+
-??? = @import("std");
8+
+const std = @import("std");
9+
10+
pub fn main() void {
11+
std.debug.print("Standard Library.\n", .{});

patches/patches/003_assignment.patch

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
37c37
2-
< const n: u8 = 50;
3-
---
4-
> var n: u8 = 50;
5-
40c40
6-
< const pi: u8 = 314159;
7-
---
8-
> const pi: u32 = 314159;
9-
42c42
10-
< const negative_eleven: u8 = -11;
11-
---
12-
> const negative_eleven: i8 = -11;
1+
--- exercises/003_assignment.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/003_assignment.zig 2023-10-05 20:04:06.856096469 +0200
3+
@@ -34,12 +34,12 @@
4+
const std = @import("std");
5+
6+
pub fn main() void {
7+
- const n: u8 = 50;
8+
+ var n: u8 = 50;
9+
n = n + 5;
10+
11+
- const pi: u8 = 314159;
12+
+ const pi: u32 = 314159;
13+
14+
- const negative_eleven: u8 = -11;
15+
+ const negative_eleven: i8 = -11;
16+
17+
// There are no errors in the next line, just explanation:
18+
// Perhaps you noticed before that the print function takes two

patches/patches/004_arrays.patch

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
30c30
2-
< const some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
3-
---
4-
> var some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
5-
43c43
6-
< const fourth = some_primes[???];
7-
---
8-
> const fourth = some_primes[3];
9-
47c47
10-
< const length = some_primes.???;
11-
---
12-
> const length = some_primes.len;
1+
--- exercises/004_arrays.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/004_arrays.zig 2023-10-05 20:04:06.859429866 +0200
3+
@@ -27,7 +27,7 @@
4+
// (Problem 1)
5+
// This "const" is going to cause a problem later - can you see what it is?
6+
// How do we fix it?
7+
- const some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
8+
+ var some_primes = [_]u8{ 1, 3, 5, 7, 11, 13, 17, 19 };
9+
10+
// Individual values can be set with '[]' notation.
11+
// Example: This line changes the first prime to 2 (which is correct):
12+
@@ -40,11 +40,11 @@
13+
// (Problem 2)
14+
// Looks like we need to complete this expression. Use the example
15+
// above to set "fourth" to the fourth element of the some_primes array:
16+
- const fourth = some_primes[???];
17+
+ const fourth = some_primes[3];
18+
19+
// (Problem 3)
20+
// Use the len property to get the length of the array:
21+
- const length = some_primes.???;
22+
+ const length = some_primes.len;
23+
24+
std.debug.print("First: {}, Fourth: {}, Length: {}\n", .{
25+
first, fourth, length,

patches/patches/005_arrays2.patch

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
28c28
2-
< const leet = ???;
3-
---
4-
> const leet = le ++ et;
5-
33c33
6-
< const bit_pattern = [_]u8{ ??? } ** 3;
7-
---
8-
> const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3;
1+
--- exercises/005_arrays2.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/005_arrays2.zig 2023-10-05 20:04:06.862763262 +0200
3+
@@ -25,12 +25,12 @@
4+
// (Problem 1)
5+
// Please set this array concatenating the two arrays above.
6+
// It should result in: 1 3 3 7
7+
- const leet = ???;
8+
+ const leet = le ++ et;
9+
10+
// (Problem 2)
11+
// Please set this array using repetition.
12+
// It should result in: 1 0 0 1 1 0 0 1 1 0 0 1
13+
- const bit_pattern = [_]u8{ ??? } ** 3;
14+
+ const bit_pattern = [_]u8{ 1, 0, 0, 1 } ** 3;
15+
16+
// Okay, that's all of the problems. Let's see the results.
17+
//

patches/patches/006_strings.patch

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
27c27
2-
< const d: u8 = ziggy[???];
3-
---
4-
> const d: u8 = ziggy[4];
5-
31c31
6-
< const laugh = "ha " ???;
7-
---
8-
> const laugh = "ha " ** 3;
9-
38c38
10-
< const major_tom = major ??? tom;
11-
---
12-
> const major_tom = major ++ " " ++ tom;
1+
--- exercises/006_strings.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/006_strings.zig 2023-10-05 20:04:06.869430053 +0200
3+
@@ -24,18 +24,18 @@
4+
// (Problem 1)
5+
// Use array square bracket syntax to get the letter 'd' from
6+
// the string "stardust" above.
7+
- const d: u8 = ziggy[???];
8+
+ const d: u8 = ziggy[4];
9+
10+
// (Problem 2)
11+
// Use the array repeat '**' operator to make "ha ha ha ".
12+
- const laugh = "ha " ???;
13+
+ const laugh = "ha " ** 3;
14+
15+
// (Problem 3)
16+
// Use the array concatenation '++' operator to make "Major Tom".
17+
// (You'll need to add a space as well!)
18+
const major = "Major";
19+
const tom = "Tom";
20+
- const major_tom = major ??? tom;
21+
+ const major_tom = major ++ " " ++ tom;
22+
23+
// That's all the problems. Let's see our results:
24+
std.debug.print("d={u} {s}{s}\n", .{ d, laugh, major_tom });

patches/patches/007_strings2.patch

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
18,20c18,20
2-
< Ziggy played guitar
3-
< Jamming good with Andrew Kelley
4-
< And the Spiders from Mars
5-
---
6-
> \\Ziggy played guitar
7-
> \\Jamming good with Andrew Kelley
8-
> \\And the Spiders from Mars
1+
--- exercises/007_strings2.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/007_strings2.zig 2023-10-05 20:04:06.872763449 +0200
3+
@@ -15,9 +15,9 @@
4+
5+
pub fn main() void {
6+
const lyrics =
7+
- Ziggy played guitar
8+
- Jamming good with Andrew Kelley
9+
- And the Spiders from Mars
10+
+ \\Ziggy played guitar
11+
+ \\Jamming good with Andrew Kelley
12+
+ \\And the Spiders from Mars
13+
;
14+
15+
std.debug.print("{s}\n", .{lyrics});

patches/patches/008_quiz.patch

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
22c22
2-
< const x: usize = 1;
3-
---
4-
> var x: usize = 1;
5-
26c26
6-
< // 'undefined'. There is no problem on this line.
7-
---
8-
> // 'undefined'. There is no error here.
9-
36c36
10-
< lang[???] = letters[x];
11-
---
12-
> lang[1] = letters[x];
13-
38,39c38,39
14-
< x = ???;
15-
< lang[2] = letters[???];
16-
---
17-
> x = 5;
18-
> lang[2] = letters[x];
1+
--- exercises/008_quiz.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/008_quiz.zig 2023-10-05 20:04:06.879430240 +0200
3+
@@ -19,11 +19,11 @@
4+
// the idiomatic type to use for array indexing.
5+
//
6+
// There IS a problem on this line, but 'usize' isn't it.
7+
- const x: usize = 1;
8+
+ var x: usize = 1;
9+
10+
// Note: When you want to declare memory (an array in this
11+
// case) without putting anything in it, you can set it to
12+
- // 'undefined'. There is no problem on this line.
13+
+ // 'undefined'. There is no error here.
14+
var lang: [3]u8 = undefined;
15+
16+
// The following lines attempt to put 'Z', 'i', and 'g' into the
17+
@@ -33,10 +33,10 @@
18+
lang[0] = letters[x];
19+
20+
x = 3;
21+
- lang[???] = letters[x];
22+
+ lang[1] = letters[x];
23+
24+
- x = ???;
25+
- lang[2] = letters[???];
26+
+ x = 5;
27+
+ lang[2] = letters[x];
28+
29+
// We want to "Program in Zig!" of course:
30+
std.debug.print("Program in {s}!\n", .{lang});

patches/patches/009_if.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
27c27
2-
< if (foo) {
3-
---
4-
> if (foo == 1) {
1+
--- exercises/009_if.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/009_if.zig 2023-10-05 20:04:06.882763636 +0200
3+
@@ -24,7 +24,7 @@
4+
const foo = 1;
5+
6+
// Please fix this condition:
7+
- if (foo) {
8+
+ if (foo == 1) {
9+
// We want our program to print this message!
10+
std.debug.print("Foo is 1!\n", .{});
11+
} else {

patches/patches/010_if2.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
13c13
2-
< const price: u8 = if ???;
3-
---
4-
> const price: u8 = if (discount) 17 else 20;
1+
--- exercises/010_if2.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/010_if2.zig 2023-10-05 20:04:06.886097032 +0200
3+
@@ -10,7 +10,7 @@
4+
5+
// Please use an if...else expression to set "price".
6+
// If discount is true, the price should be $17, otherwise $20:
7+
- const price: u8 = if ???;
8+
+ const price: u8 = if (discount) 17 else 20;
9+
10+
std.debug.print("With the discount, the price is ${}.\n", .{price});
11+
}

patches/patches/011_while.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
24c24
2-
< while (???) {
3-
---
4-
> while (n < 1024) {
1+
--- exercises/011_while.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/011_while.zig 2023-10-05 20:04:06.892763823 +0200
3+
@@ -21,7 +21,7 @@
4+
var n: u32 = 2;
5+
6+
// Please use a condition that is true UNTIL "n" reaches 1024:
7+
- while (???) {
8+
+ while (n < 1024) {
9+
// Print the current number
10+
std.debug.print("{} ", .{n});
11+

patches/patches/012_while2.patch

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
28c28
2-
< while (n < 1000) : ??? {
3-
---
4-
> while (n < 1000) : (n *= 2) {
1+
--- exercises/012_while2.zig 2023-10-03 22:15:22.122241138 +0200
2+
+++ answers/012_while2.zig 2023-10-05 20:04:06.896097219 +0200
3+
@@ -25,7 +25,7 @@
4+
5+
// Please set the continue expression so that we get the desired
6+
// results in the print statement below.
7+
- while (n < 1000) : ??? {
8+
+ while (n < 1000) : (n *= 2) {
9+
// Print the current number
10+
std.debug.print("{} ", .{n});
11+
}

0 commit comments

Comments
 (0)