From c872165aeb1bd3eadda5b354809bb3eab833f887 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 27 Aug 2016 11:10:15 +0200 Subject: Parse first --- go/queen-attack/queen_attack.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'go') diff --git a/go/queen-attack/queen_attack.go b/go/queen-attack/queen_attack.go index 536ae47..28ea34f 100644 --- a/go/queen-attack/queen_attack.go +++ b/go/queen-attack/queen_attack.go @@ -23,9 +23,6 @@ func parseLoc(l string) (int, int, error) { } func CanQueenAttack(w, b string) (bool, error) { - if w == b { - return false, errors.New("same square") - } wx, wy, err := parseLoc(w) if err != nil { return false, err @@ -34,5 +31,8 @@ func CanQueenAttack(w, b string) (bool, error) { if err != nil { return false, err } + if wx == bx && wy == by { + return false, errors.New("same square") + } return wx == bx || wy == by || abs(wx-bx) == abs(wy-by), nil } -- cgit v1.2.3