I have files which have contents that contain only "win" or "loss" like so:
win
win
loss
loss
loss
loss
win
loss
win
win
win
win
win
loss
loss
win
win
I would like to find the largest winning streak, which is the largest number of times that the word "win" has appeared on consecutive lines. In the above example, "win" appears consecutively 2 , 1, 5 and 2 times. so the largest win streak would be "5".
How can i use the Linux terminal or PHP to calculate this? The only way i can think to do it is to look for "win" then use a large number of nested if statements to check the next line, but if the win streak was over 100+ then this would result in large amounts of code. Is their examples of how this can be done more efficiently?
Aucun commentaire:
Enregistrer un commentaire