day18, example for part 2
This commit is contained in:
parent
6dabe8bc66
commit
568fdd9a70
|
@ -13,17 +13,17 @@ func Run() int {
|
||||||
log.Println("hello day 18")
|
log.Println("hello day 18")
|
||||||
log.Println("problem of lagoon bgins")
|
log.Println("problem of lagoon bgins")
|
||||||
filename := "day18/example"
|
filename := "day18/example"
|
||||||
instructions := ReadInstructionas(filename)
|
instructions := ReadInstructionas2(filename)
|
||||||
h, w := calcHeightWidth(instructions)
|
h, w := calcHeightWidth(instructions)
|
||||||
log.Printf("read %+v instructions", instructions)
|
log.Printf("read %+v instructions", instructions)
|
||||||
|
|
||||||
field := CreateField(h, w)
|
field := CreateField(h, w)
|
||||||
|
|
||||||
fmt.Println(field.String())
|
// fmt.Println(field.String())
|
||||||
borderAmount := field.digByInstructions(instructions)
|
borderAmount := field.digByInstructions(instructions)
|
||||||
log.Println(">>> created field", field.BordersFromLeft)
|
// log.Println(">>> created field", field.BordersFromLeft)
|
||||||
|
|
||||||
fmt.Println(field.String())
|
// fmt.Println(field.String())
|
||||||
// WriteToFile("borders.txt", field.String())
|
// WriteToFile("borders.txt", field.String())
|
||||||
// convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @borders.txt borders.png
|
// convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @borders.txt borders.png
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ func Run() int {
|
||||||
insideAmount := field.digInsides()
|
insideAmount := field.digInsides()
|
||||||
|
|
||||||
log.Printf("border is %d; inside is %d", borderAmount, insideAmount)
|
log.Printf("border is %d; inside is %d", borderAmount, insideAmount)
|
||||||
fmt.Println(field.String())
|
// fmt.Println(field.String())
|
||||||
// fmt.Println(field.Height, field.Width)
|
// fmt.Println(field.Height, field.Width)
|
||||||
// WriteToFile("fulldug.txt", field.String())
|
// WriteToFile("fulldug.txt", field.String())
|
||||||
// convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @fulldug.txt fulldug.png
|
// convert -size 3000x6000 xc:white -font "FreeMono" -pointsize 13 -fill black -draw @fulldug.txt fulldug.png
|
||||||
|
@ -266,9 +266,9 @@ func (f *Field) digByInstructions(instructions []Instruction) (borderAmount int)
|
||||||
borderAmount -= instructions[0].Steps
|
borderAmount -= instructions[0].Steps
|
||||||
|
|
||||||
runnerCoord := Coord{Col: 0, Row: 0}
|
runnerCoord := Coord{Col: 0, Row: 0}
|
||||||
f.Cells[runnerCoord] = &Cell{
|
// f.Cells[runnerCoord] = &Cell{
|
||||||
IsDug: true,
|
// IsDug: true,
|
||||||
}
|
// }
|
||||||
// f.confirmCoord(runnerCoord) // should be confirmed when the cycle is closed on last step
|
// f.confirmCoord(runnerCoord) // should be confirmed when the cycle is closed on last step
|
||||||
// borderAmount += 1
|
// borderAmount += 1
|
||||||
|
|
||||||
|
@ -279,20 +279,20 @@ func (f *Field) digByInstructions(instructions []Instruction) (borderAmount int)
|
||||||
if !firstInstruction {
|
if !firstInstruction {
|
||||||
turn := getTurnAsIfGoingFromLeft(prevInstruction.Direction, instruction.Direction)
|
turn := getTurnAsIfGoingFromLeft(prevInstruction.Direction, instruction.Direction)
|
||||||
for _, theTurn := range turn {
|
for _, theTurn := range turn {
|
||||||
log.Printf(">> putting turn %s", string(turn))
|
// log.Printf(">> putting turn %s", string(turn))
|
||||||
PutSymbIntoMMMMap(f.BordersFromLeft, runnerCoord.Row, runnerCoord.Col, theTurn)
|
PutSymbIntoMMMMap(f.BordersFromLeft, runnerCoord.Row, runnerCoord.Col, theTurn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
firstInstruction = false
|
firstInstruction = false
|
||||||
log.Printf("starting instruction %+v", instruction)
|
// log.Printf("starting instruction %+v", instruction)
|
||||||
for i := 0; i < instruction.Steps; i++ {
|
for i := 0; i < instruction.Steps; i++ {
|
||||||
runnerCoord = runnerCoord.applyDirection(instruction.Direction)
|
runnerCoord = runnerCoord.applyDirection(instruction.Direction)
|
||||||
f.Cells[runnerCoord] = &Cell{
|
// f.Cells[runnerCoord] = &Cell{
|
||||||
IsDug: true,
|
// IsDug: true,
|
||||||
}
|
// }
|
||||||
f.confirmCoord(runnerCoord)
|
f.confirmCoord(runnerCoord)
|
||||||
borderAmount += 1
|
borderAmount += 1
|
||||||
log.Printf("inside %+v updated border amount to %d", instruction, borderAmount)
|
// log.Printf("inside %+v updated border amount to %d", instruction, borderAmount)
|
||||||
|
|
||||||
if instruction.Direction == Upward || instruction.Direction == Downward {
|
if instruction.Direction == Upward || instruction.Direction == Downward {
|
||||||
_, alreadyCountedTurn := f.BordersFromLeft[runnerCoord.Row][runnerCoord.Col]
|
_, alreadyCountedTurn := f.BordersFromLeft[runnerCoord.Row][runnerCoord.Col]
|
||||||
|
@ -308,7 +308,7 @@ func (f *Field) digByInstructions(instructions []Instruction) (borderAmount int)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTurnAsIfGoingFromLeft(directionFrom, directionTo Direction) []BorderSymbol {
|
func getTurnAsIfGoingFromLeft(directionFrom, directionTo Direction) []BorderSymbol {
|
||||||
log.Printf("getTurnAsIfGoingFromLeft from %s to %s", directionFrom.String(), directionTo.String())
|
// log.Printf("getTurnAsIfGoingFromLeft from %s to %s", directionFrom.String(), directionTo.String())
|
||||||
|
|
||||||
var symbol BorderSymbol
|
var symbol BorderSymbol
|
||||||
if directionTo == Rightward && directionFrom == Upward {
|
if directionTo == Rightward && directionFrom == Upward {
|
||||||
|
@ -427,9 +427,9 @@ func (f *Field) digInsides() (countInside int) {
|
||||||
|
|
||||||
if bordersCrossed % 2 == 1 { // is in
|
if bordersCrossed % 2 == 1 { // is in
|
||||||
for col := prevBorder.col+1; col < specialBorder.col; col++ {
|
for col := prevBorder.col+1; col < specialBorder.col; col++ {
|
||||||
f.Cells[Coord{Col: col, Row: row}] = &Cell{
|
// f.Cells[Coord{Col: col, Row: row}] = &Cell{
|
||||||
ToBeDug: true,
|
// ToBeDug: true,
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
countInside += diff
|
countInside += diff
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,3 +28,9 @@ on last - calc with the next turn, what should be saved 'as if traversing from t
|
||||||
for L \ R - on last - calc what the turn was
|
for L \ R - on last - calc what the turn was
|
||||||
** TODO !! between last and first movement the corner is unknown.
|
** TODO !! between last and first movement the corner is unknown.
|
||||||
so, copy the first instruction to the end?
|
so, copy the first instruction to the end?
|
||||||
|
** moment of hope.
|
||||||
|
my calculation for example input for part 2
|
||||||
|
day18 result: 952408144115
|
||||||
|
|
||||||
|
952408144115
|
||||||
|
*** YES.
|
||||||
|
|
Loading…
Reference in New Issue