package day04 import ( "fmt" "regexp" "strconv" "tools" ) var roomRegexp = regexp.MustCompile(`^(.*)-([[:digit:]]+)\[(.*)\]$`) func validateChecksum(roomname, checksum string) bool { charcount := make(map[int32]int) for _, c := range roomname { if c != '-' { charcount[c]++ } } for i, c := range checksum { if i == 0 { continue } if c < int32(checksum[i-1]) || charcount[c] > charcount[int32(checksum[i-1])] { return false } } return true } func Part1(puzzle tools.AoCPuzzle) interface{} { for _, line := range puzzle.GetInputArray() { roomMatches := roomRegexp.FindStringSubmatch(line) roomName := roomMatches[1] roomSectorId, _ := strconv.Atoi(roomMatches[2]) roomChecksum := roomMatches[3] fmt.Println("Name:", roomName, "SectorID:", roomSectorId, "CheckSum:", roomChecksum) if !validateChecksum(roomName, roomChecksum) { fmt.Println("MEEP!") } } return 0 } func Part2(puzzle tools.AoCPuzzle) interface{} { return 0 }