浏览代码

Lets cut these line

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

+ 9 - 13
day14/day14.go

@@ -34,15 +34,6 @@ func setBits(number int64, mask string) int64 {
 }
 
 func processLine(line string) error {
-	if strings.Contains(line, "mask") {
-		n, err := fmt.Sscanf(line, "mask = %s\n", &mask)
-		if err != nil || n != 1 {
-			return fmt.Errorf("Error scanning '%s': %s", line, err)
-		}
-
-		return nil
-	}
-
 	var id int64
 	var number int64
 	n, err := fmt.Sscanf(line, "mem[%d] = %d", &id, &number)
@@ -64,6 +55,15 @@ func readFile(file *os.File) {
 			break
 		}
 
+		if strings.Contains(line, "mask") {
+			n, err := fmt.Sscanf(line, "mask = %s\n", &mask)
+			if err != nil || n != 1 {
+				log.Fatalf("Error scanning '%s': %s", line, err)
+			}
+
+			continue
+		}
+
 		if err := processLine(line); err != nil {
 			log.Fatal(err)
 		}
@@ -130,10 +130,6 @@ func setBitsString(number string) string {
 var mem2 map[int64]int64
 
 func processLine2(line string) error {
-	if strings.Contains(line, "mask") {
-		return nil
-	}
-
 	var id int64
 	var number int64
 	n, err := fmt.Sscanf(line, "mem[%d] = %d", &id, &number)