Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Last active January 3, 2024 20:58
Show Gist options
  • Save NicolaM94/32290881cf90b365564f28459ad5ab82 to your computer and use it in GitHub Desktop.
Save NicolaM94/32290881cf90b365564f28459ad5ab82 to your computer and use it in GitHub Desktop.
Overlapping rectangles solution
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