-
-
Save NicolaM94/32290881cf90b365564f28459ad5ab82 to your computer and use it in GitHub Desktop.
Overlapping rectangles solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
type Rectangle struct { | |
startingX int | |
startingY int | |
width int | |
height int | |
} | |
func (r Rectangle) Points() (out [][]int) { | |
for w := r.startingX; w <= r.startingX+r.width; w++ { | |
couple := []int{} | |
for h := r.startingY; h >= r.startingY-r.height; h-- { | |
couple = append(couple, w) | |
couple = append(couple, h) | |
out = append(out, couple) | |
couple = []int{} | |
} | |
} | |
return | |
} | |
func main() { | |
A := Rectangle{ | |
startingX: 1, | |
startingY: 4, | |
width: 3, | |
height: 3, | |
} | |
B := Rectangle{ | |
startingX: 0, | |
startingY: 5, | |
width: 4, | |
height: 3, | |
} | |
fmt.Println("Points of A: ", A.Points()) | |
fmt.Println("Points of B: ", B.Points()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment