Sha256: cff50f6d9cb6c1b98729761528772562a672724d9e9b669b79ddab47edff080e

Contents?: true

Size: 699 Bytes

Versions: 205

Compression:

Stored size: 699 Bytes

Contents

package queenattack

import "fmt"

const testVersion = 2

func CanQueenAttack(w, b string) (attack bool, err error) {
	if err = valSq(w); err != nil {
		return false, err
	}
	if err = valSq(b); err != nil {
		return false, err
	}
	if w == b {
		return false, fmt.Errorf("queens on same square")
	}
	if w[0] == b[0] || // same file
		w[1] == b[1] { // same rank
		return true, nil
	}
	df := w[0] - b[0]
	dr := w[1] - b[1]
	return df == dr || // same white-kingside diagonal
			df+dr == 0, // same white-queenside diagonal
		nil
}

func valSq(s string) error {
	if len(s) != 2 ||
		s[0] < 'a' || s[0] > 'h' ||
		s[1] < '1' || s[1] > '8' {
		return fmt.Errorf("invalid square: %q", s)
	}
	return nil
}

Version data entries

205 entries across 205 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.55 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.54 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.53 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.52 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.51 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.50 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.49 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.48 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.47 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.46 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.45 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.44 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.43 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.42 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.41 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.40 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.39 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.38 tracks/go/exercises/queen-attack/example.go
trackler-2.2.1.37 tracks/go/exercises/queen-attack/example.go