day9, part1
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func Run() int {
|
||||
log.Println("hello day 9")
|
||||
filename := "day9/example"
|
||||
filename := "day9/input"
|
||||
bytes, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintln("error reading file: ", err))
|
||||
@@ -67,7 +67,7 @@ type Sequence struct {
|
||||
}
|
||||
|
||||
func (s *Sequence)Next() int {
|
||||
log.Printf(">>>> trying to get next. current last known top %d\n", s.lastReadTop)
|
||||
// log.Printf(">>>> trying to get next. current last known top %d\n", s.lastReadTop)
|
||||
result := s.Get(s.lastReadTop + 1)
|
||||
s.lastReadTop += 1
|
||||
return result
|
||||
@@ -100,18 +100,18 @@ func (s *Sequence) GetAny(coord Coord) Cell {
|
||||
row, col := coord.Row, coord.Col
|
||||
if !found {
|
||||
if row == (s.zeroRowIndex - 1) {
|
||||
log.Printf("new visit to Const\n")
|
||||
// log.Printf("new visit to Const\n")
|
||||
return CachedCell(s.constRowVal)
|
||||
}
|
||||
|
||||
log.Printf("creating new uncashed at %d %d\n", row, col)
|
||||
// log.Printf("creating new uncashed at %d %d\n", row, col)
|
||||
cell = Cell{
|
||||
IsCached: false,
|
||||
Value: func() int {
|
||||
if cell.IsCached {
|
||||
return cell.SavedValue
|
||||
}
|
||||
log.Printf("calc value for %d %d cell\n", row, col)
|
||||
// log.Printf("calc value for %d %d cell\n", row, col)
|
||||
simplerCell := s.GetAny(Coord{row + 1, col - 1})
|
||||
prevCell := s.GetAny(Coord{row, col - 1})
|
||||
value := simplerCell.Value() + prevCell.Value()
|
||||
@@ -122,7 +122,7 @@ func (s *Sequence) GetAny(coord Coord) Cell {
|
||||
}
|
||||
}
|
||||
|
||||
log.Printf("in seq GetAny for %+v, got %+v", coord, cell)
|
||||
// log.Printf("in seq GetAny for %+v, got %+v", coord, cell)
|
||||
return cell
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ func SetupLowerRows(s *Sequence) {
|
||||
|
||||
inRowCalculation:
|
||||
for j := 0; true; j++ {
|
||||
log.Printf("in row %d for index %d\n", i, j)
|
||||
// log.Printf("in row %d for index %d\n", i, j)
|
||||
topRight := s.GetAny(Coord{i-1, j+1})
|
||||
topLeft := s.GetAny(Coord{i-1, j})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user