ソースを参照

Thinking about part2

Piotr Czajkowski 3 年 前
コミット
b64fe8f1a0
1 ファイル変更11 行追加0 行削除
  1. 11 0
      day19/day19.go

+ 11 - 0
day19/day19.go

@@ -105,16 +105,23 @@ func buildStringsForRule(ruleID int, stringsSoFar []string) []string {
 	return newStrings
 }
 
+var notMatched []string
+
 func part1(validStrings []string) int {
 	valid := 0
 
 	for _, message := range messages {
+		matched := false
 		for _, item := range validStrings {
 			if message == item {
 				valid++
+				matched = true
 				break
 			}
 		}
+		if !matched {
+			notMatched = append(notMatched, message)
+		}
 	}
 
 	return valid
@@ -139,4 +146,8 @@ func main() {
 
 	validStrings := buildStringsForRule(0, []string{""})
 	fmt.Println("Part1:", part1(validStrings))
+
+	fmt.Println(notMatched)
+	fmt.Println("42:", buildStringsForRule(42, []string{""}))
+	fmt.Println("31:", buildStringsForRule(31, []string{""}))
 }