Skip to content

Instantly share code, notes, and snippets.

@PirosB3
Created December 22, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PirosB3/f3f2af7d1b223efddadb to your computer and use it in GitHub Desktop.
Save PirosB3/f3f2af7d1b223efddadb to your computer and use it in GitHub Desktop.
table.go
package main
import "fmt"
type Grid []uint
func (g *Grid) NewGrid(width int, height int) {
for i:=0; i < height; i++ {
*g = append(*g, 0)
}
}
func (g Grid) TurnOn(x int, y int, x1 int, y1 int) {
var applyer uint = 1 << uint(9 - x)
applyer -= 1
lower := uint(1 << uint(9 - x1)) - 1
applyer &= ^lower
for i := y; i < y1; i++ {
g[i] |= applyer
}
}
func (g Grid) Println(width int, height int) {
for i := 0 ; i < height; i++ {
h := make([]int, width)
for j :=0; j < width; j++ {
if g[i] & (1 << uint(9-j-1)) > 0 {
h[j] = 1
} else {
h[j] = 0
}
}
fmt.Println(h)
}
}
func main() {
var g Grid
g.NewGrid(9, 9)
g.TurnOn(2, 1, 4, 4)
g.TurnOn(3, 5, 8, 8)
g.TurnOn(8, 0, 9, 3)
g.Println(9, 9)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment