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("problem of lagoon bgins")
|
||||
filename := "day18/example"
|
||||
instructions := ReadInstructionas(filename)
|
||||
instructions := ReadInstructionas2(filename)
|
||||
h, w := calcHeightWidth(instructions)
|
||||
log.Printf("read %+v instructions", instructions)
|
||||
|
||||
field := CreateField(h, w)
|
||||
|
||||
fmt.Println(field.String())
|
||||
// fmt.Println(field.String())
|
||||
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())
|
||||
// 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()
|
||||
|
||||
log.Printf("border is %d; inside is %d", borderAmount, insideAmount)
|
||||
fmt.Println(field.String())
|
||||
// fmt.Println(field.String())
|
||||
// fmt.Println(field.Height, field.Width)
|
||||
// WriteToFile("fulldug.txt", field.String())
|
||||
// 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
|
||||
|
||||
runnerCoord := Coord{Col: 0, Row: 0}
|
||||
f.Cells[runnerCoord] = &Cell{
|
||||
IsDug: true,
|
||||
}
|
||||
// f.Cells[runnerCoord] = &Cell{
|
||||
// IsDug: true,
|
||||
// }
|
||||
// f.confirmCoord(runnerCoord) // should be confirmed when the cycle is closed on last step
|
||||
// borderAmount += 1
|
||||
|
||||
|
@ -279,20 +279,20 @@ func (f *Field) digByInstructions(instructions []Instruction) (borderAmount int)
|
|||
if !firstInstruction {
|
||||
turn := getTurnAsIfGoingFromLeft(prevInstruction.Direction, instruction.Direction)
|
||||
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)
|
||||
}
|
||||
}
|
||||
firstInstruction = false
|
||||
log.Printf("starting instruction %+v", instruction)
|
||||
// log.Printf("starting instruction %+v", instruction)
|
||||
for i := 0; i < instruction.Steps; i++ {
|
||||
runnerCoord = runnerCoord.applyDirection(instruction.Direction)
|
||||
f.Cells[runnerCoord] = &Cell{
|
||||
IsDug: true,
|
||||
}
|
||||
// f.Cells[runnerCoord] = &Cell{
|
||||
// IsDug: true,
|
||||
// }
|
||||
f.confirmCoord(runnerCoord)
|
||||
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 {
|
||||
_, 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 {
|
||||
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
|
||||
if directionTo == Rightward && directionFrom == Upward {
|
||||
|
@ -427,9 +427,9 @@ func (f *Field) digInsides() (countInside int) {
|
|||
|
||||
if bordersCrossed % 2 == 1 { // is in
|
||||
for col := prevBorder.col+1; col < specialBorder.col; col++ {
|
||||
f.Cells[Coord{Col: col, Row: row}] = &Cell{
|
||||
ToBeDug: true,
|
||||
}
|
||||
// f.Cells[Coord{Col: col, Row: row}] = &Cell{
|
||||
// ToBeDug: true,
|
||||
// }
|
||||
}
|
||||
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
|
||||
** TODO !! between last and first movement the corner is unknown.
|
||||
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