浏览代码

Preparing for part2

Piotr Czajkowski 1 年之前
父节点
当前提交
1a1938ffad
共有 1 个文件被更改,包括 9 次插入4 次删除
  1. 9 4
      16/code.go

+ 9 - 4
16/code.go

@@ -164,11 +164,8 @@ func count(board [][]byte) int {
 	return result
 }
 
-func part1(board [][]byte) int {
-	height := len(board)
-	width := len(board[0])
+func processBeams(board [][]byte, height int, width int, beams []Beam) int {
 	trackBoard := emptyBoard(height, width)
-	beams := []Beam{Beam{pos: Point{y: 0, x: 0, direction: East}, wasHere: make(map[Point]bool)}}
 	pastBeams := make(map[Point]bool)
 	pastBeams[beams[0].pos] = true
 
@@ -192,6 +189,14 @@ func part1(board [][]byte) int {
 	return count(trackBoard)
 }
 
+func part1(board [][]byte) int {
+	height := len(board)
+	width := len(board[0])
+	beams := []Beam{Beam{pos: Point{y: 0, x: 0, direction: East}, wasHere: make(map[Point]bool)}}
+
+	return processBeams(board, height, width, beams)
+}
+
 func main() {
 	if len(os.Args) < 2 {
 		log.Fatal("You need to specify a file!")