func (clock *ballClock) updFiveMinTrack(ballVal int) { if len(clock.fiveMinTrack) == fiveMinTrackCapacity { for len(clock.fiveMinTrack) > 0 { lastVal := 0 lastVal, clock.fiveMinTrack = slice.Pop(clock.fiveMinTrack) clock.ballq = slice.Push(clock.ballq, lastVal) } clock.updHourTrack(ballVal) } else { clock.fiveMinTrack = slice.Push(clock.fiveMinTrack, ballVal) } }
func (clock *ballClock) updMinTrack(ballVal int) { if len(clock.minTrack) == minTrackCapacity { //Put the balls on the track in reverse order //back into the ballq for len(clock.minTrack) > 0 { lastVal := 0 lastVal, clock.minTrack = slice.Pop(clock.minTrack) clock.ballq = slice.Push(clock.ballq, lastVal) } //Put the next ball from ballq into the next track clock.updFiveMinTrack(ballVal) } else { clock.minTrack = slice.Push(clock.minTrack, ballVal) } }
func (clock *ballClock) updHourTrack(ballVal int) { if len(clock.hourTrack) == hourTrackCapacity { for len(clock.hourTrack) > 0 { lastVal := 0 lastVal, clock.hourTrack = slice.Pop(clock.hourTrack) clock.ballq = slice.Push(clock.ballq, lastVal) } clock.ballq = slice.Push(clock.ballq, ballVal) clock.halfDays += 1 } else { clock.hourTrack = slice.Push(clock.hourTrack, ballVal) } if slice.Same(clock.ballq, clock.orig) { clock.done = true } }