my ziglings
0

Configure Feed

Select the types of activity you want to include in your feed.

Normalized exercise output, answers (#41)

1. All exercises should print a trailing \n
2. The build script should always show you _exactly_ what it's looking
for when you get it wrong. Therefore, .output should be set to the
exact expected output.

Dave Gauer (Apr 4, 2021, 4:29 PM EDT) cc010139 8bb916d7

+17 -16
+10 -10
build.zig
··· 73 73 }, 74 74 .{ 75 75 .main_file = "007_strings2.zig", 76 - .output = "Ziggy", 76 + .output = "Ziggy played guitar\nJamming good with Andrew Kelley\nAnd the Spiders from Mars", 77 77 .hint = "Please fix the lyrics!", 78 78 }, 79 79 .{ 80 80 .main_file = "008_quiz.zig", 81 - .output = "Program in Zig", 81 + .output = "Program in Zig!", 82 82 .hint = "See if you can fix the program!", 83 83 }, 84 84 .{ ··· 87 87 }, 88 88 .{ 89 89 .main_file = "010_if2.zig", 90 - .output = "price is $17", 90 + .output = "With the discount, the price is $17.", 91 91 }, 92 92 .{ 93 93 .main_file = "011_while.zig", 94 - .output = "n=1024", 94 + .output = "2 4 8 16 32 64 128 256 512 n=1024", 95 95 .hint = "You probably want a 'less than' condition.", 96 96 }, 97 97 .{ 98 98 .main_file = "012_while2.zig", 99 - .output = "n=1024", 99 + .output = "2 4 8 16 32 64 128 256 512 n=1024", 100 100 .hint = "It might help to look back at the previous exercise.", 101 101 }, 102 102 .{ ··· 117 117 }, 118 118 .{ 119 119 .main_file = "017_quiz2.zig", 120 - .output = "8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16", 120 + .output = "1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16,", 121 121 .hint = "This is a famous game!", 122 122 }, 123 123 .{ 124 124 .main_file = "018_functions.zig", 125 - .output = "Question: 42", 125 + .output = "Answer to the Ultimate Question: 42", 126 126 .hint = "Can you help write the function?", 127 127 }, 128 128 .{ ··· 158 158 }, 159 159 .{ 160 160 .main_file = "026_hello2.zig", 161 - .output = "Hello world", 161 + .output = "Hello world!", 162 162 .hint = "Try using a try!", 163 163 .check_stdout = true, 164 164 }, ··· 204 204 }, 205 205 .{ 206 206 .main_file = "036_enums2.zig", 207 - .output = "#0000ff", 207 + .output = "<p>\n <span style=\"color: #ff0000\">Red</span>\n <span style=\"color: #00ff00\">Green</span>\n <span style=\"color: #0000ff\">Blue</span>\n</p>", 208 208 .hint = "I'm feeling blue about this.", 209 209 }, 210 210 .{ ··· 213 213 }, 214 214 .{ 215 215 .main_file = "038_structs2.zig", 216 - .output = "Character 2 - G:10 H:100 XP:20", 216 + .output = "Character 1 - G:20 H:100 XP:10\nCharacter 2 - G:10 H:100 XP:20", 217 217 }, 218 218 .{ 219 219 .main_file = "039_pointers.zig",
+1 -1
exercises/022_errors2.zig
··· 25 25 // an error. Can you set the type correctly above? 26 26 my_number = MyNumberError.TooSmall; 27 27 28 - std.debug.print("I compiled!", .{}); 28 + std.debug.print("I compiled!\n", .{}); 29 29 }
+1 -1
exercises/023_errors3.zig
··· 14 14 var a: u32 = addTwenty(44) catch 22; 15 15 var b: u32 = addTwenty(4) ??? 22; 16 16 17 - std.debug.print("a={}, b={}", .{ a, b }); 17 + std.debug.print("a={}, b={}\n", .{ a, b }); 18 18 } 19 19 20 20 // Please provide the return type from this function.
+1 -1
exercises/024_errors4.zig
··· 25 25 var b: u32 = makeJustRight(14) catch 0; 26 26 var c: u32 = makeJustRight(4) catch 0; 27 27 28 - std.debug.print("a={}, b={}, c={}", .{ a, b, c }); 28 + std.debug.print("a={}, b={}, c={}\n", .{ a, b, c }); 29 29 } 30 30 31 31 // In this silly example we've split the responsibility of making
+1 -1
exercises/025_errors5.zig
··· 19 19 var b: u32 = addFive(14) catch 0; 20 20 var c: u32 = addFive(4) catch 0; 21 21 22 - std.debug.print("a={}, b={}, c={}", .{ a, b, c }); 22 + std.debug.print("a={}, b={}, c={}\n", .{ a, b, c }); 23 23 } 24 24 25 25 fn addFive(n: u32) MyNumberError!u32 {
+1
exercises/036_enums2.zig
··· 53 53 \\ <span style="color: #{x:0>6}">Green</span> 54 54 \\ <span style="color: #{}">Blue</span> 55 55 \\</p> 56 + \\ 56 57 , .{ 57 58 @enumToInt(Color.red), 58 59 @enumToInt(Color.green),
+1 -1
exercises/037_structs.zig
··· 52 52 // Ouch! Glorp takes a punch! 53 53 glorp_the_wise.health -= 10; 54 54 55 - std.debug.print("Your wizard has {} health and {} gold.", .{ 55 + std.debug.print("Your wizard has {} health and {} gold.\n", .{ 56 56 glorp_the_wise.health, 57 57 glorp_the_wise.gold, 58 58 });
+1 -1
exercises/043_pointers5.zig
··· 73 73 .warrior => "Warrior", 74 74 }; 75 75 76 - std.debug.print("{s} (G:{} H:{} XP:{})", .{ 76 + std.debug.print("{s} (G:{} H:{} XP:{})\n", .{ 77 77 class_name, 78 78 c.gold, 79 79 c.health,