day10, example last
This commit is contained in:
parent
71262cabe7
commit
69cf6b9aaf
|
@ -41,6 +41,13 @@ func Run() int {
|
||||||
// fmt.Println(fieldMap.String())
|
// fmt.Println(fieldMap.String())
|
||||||
fmt.Println("beore marking closest Outer:")
|
fmt.Println("beore marking closest Outer:")
|
||||||
// now main loop is closed with regards to 'S' neighbors
|
// now main loop is closed with regards to 'S' neighbors
|
||||||
|
|
||||||
|
|
||||||
|
// TODO Hardcode change S to correct Title
|
||||||
|
fixedBeast := fieldMap.Cells[fieldMap.BeastCoord]
|
||||||
|
fixedBeast.Tile = '7'
|
||||||
|
fieldMap.Cells[fieldMap.BeastCoord] = fixedBeast
|
||||||
|
|
||||||
fieldMap.countIntersectionsTopDown()
|
fieldMap.countIntersectionsTopDown()
|
||||||
// fieldMap.initialMarkOuter()
|
// fieldMap.initialMarkOuter()
|
||||||
fmt.Println("after marking closest Outer:")
|
fmt.Println("after marking closest Outer:")
|
||||||
|
@ -140,6 +147,7 @@ type Map struct {
|
||||||
|
|
||||||
func (m *Map) String() string {
|
func (m *Map) String() string {
|
||||||
result := ""
|
result := ""
|
||||||
|
result += fmt.Sprintf("map of height %d and with %d\n", m.Height, m.Width)
|
||||||
for y := 0; y < m.Height; y++ {
|
for y := 0; y < m.Height; y++ {
|
||||||
for x := 0; x < m.Width; x++ {
|
for x := 0; x < m.Width; x++ {
|
||||||
cell := m.Cells[Coord{x, y}]
|
cell := m.Cells[Coord{x, y}]
|
||||||
|
@ -270,7 +278,9 @@ func Read(filename string) Map {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprint("cannot read file ", filename))
|
panic(fmt.Sprint("cannot read file ", filename))
|
||||||
}
|
}
|
||||||
lines := strings.Split(string(bytes), "\n")
|
text := string(bytes)
|
||||||
|
text = strings.TrimSpace(text)
|
||||||
|
lines := strings.Split(text, "\n")
|
||||||
result.Height = len(lines)
|
result.Height = len(lines)
|
||||||
result.Width = len(lines[0])
|
result.Width = len(lines[0])
|
||||||
result.Cells = map[Coord]Cell{}
|
result.Cells = map[Coord]Cell{}
|
||||||
|
@ -351,30 +361,78 @@ func (c *Cell) OutDirections() []Direction {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Map)countIntersectionsTopDown() {
|
func (m *Map)countIntersectionsTopDown() {
|
||||||
buffer := make([][]int, m.Height)
|
stacks := make([][]rune, m.Width) // stack for each X
|
||||||
for y := 0; y < m.Height; y++ {
|
for y := 0; y < m.Height; y++ {
|
||||||
buffer[y] = make([]int, m.Width)
|
|
||||||
for x := 0; x < m.Width; x++ {
|
for x := 0; x < m.Width; x++ {
|
||||||
if y > 0 {
|
stack := stacks[x]
|
||||||
buffer[y][x] = buffer[y-1][x]
|
len := len(stack)
|
||||||
}
|
|
||||||
cell := m.Cells[Coord{x, y}]
|
cell := m.Cells[Coord{x, y}]
|
||||||
if !cell.IsOnMainPath && buffer[y][x] % 2 == 0 {
|
if cell.IsOnMainPath {
|
||||||
log.Printf("not main path y=%d x=%d cell is even", y, x)
|
if len == 0 {
|
||||||
|
stack = append(stack, cell.Tile)
|
||||||
|
} else {
|
||||||
|
top := stack[len-1]
|
||||||
|
if isOpposite(top, cell.Tile) {
|
||||||
|
stack = stack[:len-1]
|
||||||
|
} else if isScrunching(top, cell.Tile) {
|
||||||
|
stack = stack[:len-1]
|
||||||
|
stack = append(stack, '-')
|
||||||
|
stack, _ = popTwoHorizontals(stack)
|
||||||
|
} else if cell.Tile != '|' {
|
||||||
|
stack = append(stack, cell.Tile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stacks[x] = stack
|
||||||
|
} else {
|
||||||
|
if len == 0 {
|
||||||
m.markOuter(cell.Coord)
|
m.markOuter(cell.Coord)
|
||||||
}
|
}
|
||||||
pathEnds := !slices.Contains(cell.OutDirections(), DOWN)
|
|
||||||
if cell.IsOnMainPath && pathEnds {
|
|
||||||
log.Printf("iter y=%d x=%d increasing for %+v\n", y, x, cell)
|
|
||||||
if y > 0 {
|
|
||||||
buffer[y][x] = buffer[y-1][x] + 1
|
|
||||||
} else {
|
|
||||||
buffer[y][x] = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(buffer)
|
for x := 0; x < m.Width; x++ {
|
||||||
|
stack := stacks[x]
|
||||||
|
fmt.Println(string(stack))
|
||||||
|
}
|
||||||
|
fmt.Print(stacks)
|
||||||
|
}
|
||||||
|
|
||||||
|
func popTwoHorizontals(stack []rune) ([]rune, bool) {
|
||||||
|
len := len(stack)
|
||||||
|
if len >= 2 {
|
||||||
|
top := stack[len-1]
|
||||||
|
prev := stack[len-2]
|
||||||
|
if top == '-' && prev == '-' {
|
||||||
|
return stack[:len-2], true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stack, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isScrunching(pipe, other rune) bool {
|
||||||
|
switch pipe {
|
||||||
|
case 'F':
|
||||||
|
return other == 'J'
|
||||||
|
case '7':
|
||||||
|
return other == 'L'
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isOpposite(pipe, other rune) bool {
|
||||||
|
switch pipe {
|
||||||
|
case '-':
|
||||||
|
return other == '-'
|
||||||
|
case 'L':
|
||||||
|
return other == 'F'
|
||||||
|
case 'J':
|
||||||
|
return other == '7'
|
||||||
|
case 'F':
|
||||||
|
return other == 'L'
|
||||||
|
case '7':
|
||||||
|
return other == 'J'
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,3 +157,12 @@ and some elements take off?
|
||||||
** ok, one more attempt?
|
** ok, one more attempt?
|
||||||
not counting, but maintaining a stack?
|
not counting, but maintaining a stack?
|
||||||
and opposite angles take the element off the stack?
|
and opposite angles take the element off the stack?
|
||||||
|
|
||||||
|
so - takes off -
|
||||||
|
and any left braket takes off any right bracket
|
||||||
|
|
||||||
|
and two bottom angles shouldn't be allowed to counteract one another, but top & bottom should be balanced anyway
|
||||||
|
** uh. so many more updates.
|
||||||
|
and i'll need to owerwrite S to it's value somehow
|
||||||
|
|
||||||
|
i will change the S myself. by hardcode
|
||||||
|
|
Loading…
Reference in New Issue