Jun-06-2020, 09:45 PM
Hello,
Python (coding in general) newbie, so please forgive me if the question is naive/ I did do a search before asking, but I have not found an answer that fits.
I am trying to show than in a random series of integers, it is perfectly possible to find a sequence of repeating integers that does not look random. To do so, I create a numpy array (in a Jupyter notebook)which I populate with a random.randint to simulate dice throws:
[python] seq = np.random.randint(1, 7, size = 100) [python]
The size is set to 100 arbitrarily. I may want to increase or decrease the size of the array.
Where I get stuck is writing the loop to check the longest running sequence of repeating integers. I am also at a loss for deciding how to deal with cases when there are several sequences of repeating integers of the same length that are the longest sequences. I would like to identify the them all in that case. Either way, I would like to determine the length of the longest sequence(s) and the integer(s) concerned.
For example, here is a run generated with the randit():
-----Generated Random Array----
[2 4 3 3 1 3 1 4 4 2 1 6 5 5 5 1 4 6 3 6 1 5 2 6 3 1 1 5 4 1 3 5 1 4 2 2 6
2 3 1 5 3 1 6 4 5 4 6 5 6 5 6 6 5 5 1 4 2 3 3 5 2 5 1 3 4 3 4 6 6 5 6 1 2
3 2 2 3 2 3 1 5 6 3 3 3 5 3 1 5 6 3 2 2 1 1 4 1 4 1]
If I am not mistaken, the longest running sequences of repeating integers are the 555 and 333 I have highlighted. How do I pick them both out programmatically and show both the length of the sequence and the associated integer?
Thank you for your suggestions and your patience.
Python (coding in general) newbie, so please forgive me if the question is naive/ I did do a search before asking, but I have not found an answer that fits.
I am trying to show than in a random series of integers, it is perfectly possible to find a sequence of repeating integers that does not look random. To do so, I create a numpy array (in a Jupyter notebook)which I populate with a random.randint to simulate dice throws:
[python] seq = np.random.randint(1, 7, size = 100) [python]
The size is set to 100 arbitrarily. I may want to increase or decrease the size of the array.
Where I get stuck is writing the loop to check the longest running sequence of repeating integers. I am also at a loss for deciding how to deal with cases when there are several sequences of repeating integers of the same length that are the longest sequences. I would like to identify the them all in that case. Either way, I would like to determine the length of the longest sequence(s) and the integer(s) concerned.
For example, here is a run generated with the randit():
-----Generated Random Array----
[2 4 3 3 1 3 1 4 4 2 1 6 5 5 5 1 4 6 3 6 1 5 2 6 3 1 1 5 4 1 3 5 1 4 2 2 6
2 3 1 5 3 1 6 4 5 4 6 5 6 5 6 6 5 5 1 4 2 3 3 5 2 5 1 3 4 3 4 6 6 5 6 1 2
3 2 2 3 2 3 1 5 6 3 3 3 5 3 1 5 6 3 2 2 1 1 4 1 4 1]
If I am not mistaken, the longest running sequences of repeating integers are the 555 and 333 I have highlighted. How do I pick them both out programmatically and show both the length of the sequence and the associated integer?
Thank you for your suggestions and your patience.