so, have created program runs in 2 parts. firstly, generate list of 500 random numbers , store them in text file. secondly, required find max, min, average, etc. however, supposed find how many consecutive numbers come up. problem lies. not sure how approach it.
looking place start.
thank you
as go along array keep list of following things: current largest seen element, current smallest seen, total of elements seen far, ..., last element seen & total count of consecutive numbers. if current number == last element seen + 1, increase consecutive count. there should flag first element in consecutive sequence, that, say, {1, 2}
counted 2 occurrences instead of one
last_seen = -1 previous_consecutive = false for(x in numbers_list): if x == last_seen + 1: if not previous_consecutive: number_of_consecutive_elements += 1 number_of_consecutive_elements += 1 previous_consecutive = true else: previous_consecutive = false last_seen = x
Comments
Post a Comment