Ver Fonte

Getting valid tickets

Piotr Czajkowski há 3 anos atrás
pai
commit
540df35727
1 ficheiros alterados com 9 adições e 0 exclusões
  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)
 }