Revised exercises due to the changes of Zig version 0.11.0-dev.3853

This commit is contained in:
Chris Boesch 2023-06-26 23:43:39 +02:00
parent a57926bef2
commit a0a9920b78
11 changed files with 16 additions and 13 deletions

View file

@ -29,7 +29,8 @@ pub fn main() void {
// Note that we convert the usize i to a u32 with
// @intCast(), a builtin function just like @import().
// We'll learn about these properly in a later exercise.
const place_value = std.math.pow(u32, 2, @intCast(u32, i));
const i_u32: u32 = @intCast(i);
const place_value = std.math.pow(u32, 2, i_u32);
value += place_value * bit;
}

View file

@ -429,7 +429,7 @@ fn printTrip(trip: []?TripItem) void {
// We convert the usize length to a u8 with @intCast(), a
// builtin function just like @import(). We'll learn about
// these properly in a later exercise.
var i: u8 = @intCast(u8, trip.len);
var i: u8 = @intCast(trip.len);
while (i > 0) {
i -= 1;

View file

@ -47,7 +47,7 @@ fn makeSequence(comptime T: type, ??? size: usize) [???]T {
var i: usize = 0;
while (i < size) : (i += 1) {
sequence[i] = @intCast(T, i) + 1;
sequence[i] = @as(T, @intCast(i)) + 1;
}
return sequence;

View file

@ -204,7 +204,7 @@ pub fn main() void {
}
fn printTrip(trip: []?TripItem) void {
var i: u8 = @intCast(u8, trip.len);
var i: u8 = @intCast(trip.len);
while (i > 0) {
i -= 1;

View file

@ -45,7 +45,8 @@ fn runningAverage(arr: []const f64, avg: []f64) void {
for (0.., arr) |index, val| {
sum += val;
avg[index] = sum / @floatFromInt(f64, index + 1);
const f_index: f64 = @floatFromInt(index + 1);
avg[index] = sum / f_index;
}
}

View file

@ -53,7 +53,7 @@ fn isPangram(str: []const u8) bool {
// and are numbered sequentially, we simply subtract the
// first letter (in this case the 'a') from the character
// found, and thus get the position of the desired bit
bits |= @as(u32, 1) << @truncate(u5, ascii.toLower(c) - 'a');
bits |= @as(u32, 1) << @truncate(ascii.toLower(c) - 'a');
}
}
// last we return the comparison if all 26 bits are set,