reset password
Author Message
304374842
Posts: 56
Posted 16:13 May 21, 2016 |

I am confused about what question 4 is actually asking us to do.  I get that the user says how many times they want to roll the die, but I don't get what the output is supposed to be.  Can anyone explain?

rcamach7
Posts: 31
Posted 16:26 May 21, 2016 |

The output is supposed to group any similar results (called runs) together using '(' and ')'. So if you rolled the dice 4 times and got 5 3 2 2, the output should be 5 3 (2 2). 

I'm still trying to figure out a way to group the results, it seems kinda tricky.

kknaur
Posts: 540
Posted 17:56 May 21, 2016 |

Correct, any series of repeated numbers should be grouped with parenthesis in the output, i.e. 1 2 2 2 2 3 3 4 5 4 5 5 5 5 6 6 would be

1 (2 2 2 2) (3 3) 4 5 4 (5 5 5 5) (6 6)

The trick with this one is that you have to look one position ahead to see if you should either print an opening parenthesis or print a closing one after an opening has already been printed.  Also keep in mind that when you look ahead if you try to look ahead when you are at the last index you will get an out of bounds exception.

304374842
Posts: 56
Posted 19:09 May 21, 2016 |

Thanks I get it now.

304374842
Posts: 56
Posted 10:51 May 23, 2016 |

I'm having a lot of problems with the out of bounds error.  Any hints on how to fix that?

kknaur
Posts: 540
Posted 14:33 May 23, 2016 |

Figure out exactly why it is going out of bounds and then think about how to fix it.  The shifting array example I showed in class uses a similar technique for referring to the current element and the previous element in the array without going out of bounds.  This might give you a hint of something to think about, only in our case we are looking ahead instead of looking behind...

Last edited by kknaur at 14:34 May 23, 2016.