Implemented hotelbuisness
This commit is contained in:
parent
750eaed481
commit
7d9db66ec7
1 changed files with 28 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package hotelbusiness
|
package hotelbusiness
|
||||||
|
|
||||||
|
import "math"
|
||||||
|
|
||||||
type Guest struct {
|
type Guest struct {
|
||||||
CheckInDate int
|
CheckInDate int
|
||||||
CheckOutDate int
|
CheckOutDate int
|
||||||
|
@ -13,5 +15,30 @@ type Load struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ComputeLoad(guests []Guest) []Load {
|
func ComputeLoad(guests []Guest) []Load {
|
||||||
|
if len(guests) == 0 {
|
||||||
return []Load{}
|
return []Load{}
|
||||||
}
|
}
|
||||||
|
minDate, maxDate := math.MaxInt, math.MinInt
|
||||||
|
loadsNoEmptyDays := make(map[int]int)
|
||||||
|
for _, guest := range guests {
|
||||||
|
if guest.CheckInDate < minDate {
|
||||||
|
minDate = guest.CheckInDate
|
||||||
|
}
|
||||||
|
if guest.CheckOutDate > maxDate {
|
||||||
|
maxDate = guest.CheckOutDate
|
||||||
|
}
|
||||||
|
for i := guest.CheckInDate; i < guest.CheckOutDate; i++ {
|
||||||
|
loadsNoEmptyDays[i]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
loads, prevGuestCount := make([]Load, 0), 0
|
||||||
|
for i := minDate; i <= maxDate; i++ {
|
||||||
|
guestCount := loadsNoEmptyDays[i]
|
||||||
|
if prevGuestCount == guestCount {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
loads = append(loads, Load{i, guestCount})
|
||||||
|
prevGuestCount = guestCount
|
||||||
|
}
|
||||||
|
return loads
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue