Prechádzať zdrojové kódy

Getting valid tickets

Piotr Czajkowski 3 rokov pred
rodič
commit
540df35727
1 zmenil súbory, kde vykonal 9 pridanie a 0 odobranie
  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)
 }