浏览代码

Getting valid tickets

Piotr Czajkowski 3 年之前
父节点
当前提交
540df35727
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      day16/day16.go

+ 9 - 0
day16/day16.go

@@ -86,16 +86,24 @@ func checkAllRulesOnField(field int) bool {
 	return false
 }
 
+var validTickets []ticket
+
 func sumBad() int {
 	numberOfTickets := len(tickets)
 	sum := 0
 
 	for i := 1; i < numberOfTickets; i++ {
+		validTicket := true
 		for _, field := range tickets[i] {
 			if !checkAllRulesOnField(field) {
 				sum += field
+				validTicket = false
 			}
 		}
+
+		if validTicket {
+			validTickets = append(validTickets, tickets[i])
+		}
 	}
 
 	return sum
@@ -119,4 +127,5 @@ func main() {
 	}
 
 	fmt.Println("Part1:", sumBad())
+	fmt.Println(validTickets)
 }