052_slices.patch 716 B

12345678910111213141516171819202122
  1. --- exercises/052_slices.zig 2023-10-03 22:15:22.122241138 +0200
  2. +++ answers/052_slices.zig 2023-10-05 20:04:07.079433985 +0200
  3. @@ -32,8 +32,8 @@
  4. var cards = [8]u8{ 'A', '4', 'K', '8', '5', '2', 'Q', 'J' };
  5. // Please put the first 4 cards in hand1 and the rest in hand2.
  6. - const hand1: []u8 = cards[???];
  7. - const hand2: []u8 = cards[???];
  8. + const hand1: []u8 = cards[0..4];
  9. + const hand2: []u8 = cards[4..];
  10. std.debug.print("Hand1: ", .{});
  11. printHand(hand1);
  12. @@ -43,7 +43,7 @@
  13. }
  14. // Please lend this function a hand. A u8 slice hand, that is.
  15. -fn printHand(hand: ???) void {
  16. +fn printHand(hand: []u8) void {
  17. for (hand) |h| {
  18. std.debug.print("{u} ", .{h});
  19. }