Skip to content

Commit

Permalink
exercises(queen-attack): example: fix for Zig 0.12.0-dev (#368)
Browse files Browse the repository at this point in the history
Resolve this error, which occured with the latest Zig master release:

    $ zig version
    0.12.0-dev.2341+92211135f
    $ bin/run-tests queen-attack
    Running tests for queen-attack...
    queen_attack.zig:28:18: error: root struct of file 'math' has no member named 'absInt'
                (math.absInt(self.row - other.row) catch unreachable ==
                 ~~~~^~~~~~~
    /opt/zig/lib/std/math.zig:1:1: note: struct declared here
    const builtin = @import("builtin");
    ^~~~~
    referenced by:
        test.cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal: test_queen_attack.zig:87:34
        remaining reference traces hidden; use '-freference-trace' to see all reference traces
  • Loading branch information
ee7 authored Jan 25, 2024
1 parent 7c1dc95 commit 9cb56b3
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions exercises/practice/queen-attack/.meta/example.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const std = @import("std");
const math = std.math;

pub const QueenError = error{
InitializationFailure,
Expand All @@ -24,8 +23,8 @@ pub const Queen = struct {
if (self.row == other.row and self.col == other.col) {
return QueenError.InvalidAttack;
}
return (self.row == other.row) or (self.col == other.col) or
(math.absInt(self.row - other.row) catch unreachable ==
math.absInt(self.col - other.col) catch unreachable);
const row_diff = self.row - other.row;
const col_diff = self.col - other.col;
return (row_diff == 0) or (col_diff == 0) or (row_diff == col_diff) or (row_diff == -col_diff);
}
};

0 comments on commit 9cb56b3

Please sign in to comment.