package main import ( "fmt" ) func AssignExtraRooms(rooms []RoomFolder, roomsPerNight int) { latestnight := 0 for _, r := range rooms { if r.Cfg.night > latestnight { latestnight = r.Cfg.night } } night := latestnight + 1 room := 1 for i, r := range rooms { if r.Cfg.night > 0 { continue } rooms[i].Cfg.night = night rooms[i].Cfg.room = room room++ if room > roomsPerNight { room = 1 night++ } } } func CheckDuplicateRooms(rooms []RoomFolder) error { maxnight := 0 maxroom := 0 for _, r := range rooms { if r.Cfg.night > maxnight { maxnight = r.Cfg.night } if r.Cfg.room > maxroom { maxroom = r.Cfg.room } } assignments := make([][]string, maxnight) for night := range maxnight { assignments[night] = make([]string, maxroom) } for _, r := range rooms { if r.Cfg.night > 0 && r.Cfg.room > 0 { if assignments[r.Cfg.night-1][r.Cfg.room-1] != "" { return fmt.Errorf("duplicate room assignment for Room %d Night %d: %s, %s", r.Cfg.night, r.Cfg.room, assignments[r.Cfg.night][r.Cfg.room], r.Path) } assignments[r.Cfg.night-1][r.Cfg.room-1] = r.Path } } return nil }