Problem 24 ( pseudo ) Random Generator

Back to Problem Solutions forum

shatseli     2020-02-14 14:24:27

Dear Brothers and Sisters, please kindly advice : To check the previous occurence of element in ArrayList I use the ".contains(value)" method and upon receiving boolean == true I am performing on a second step the ".indexOf(value)" method.

Looks like seems logic, isn't it ?

But ... Unfortunately all the receiving index values which I was submited then were exactly less on 3 than the Correct ones ( difference = 3 between the Correct values and mines )

What I did not concerned correctly in both those methods implementation ?

Thank you in advance ( fragments of code are below ):

    // previously 1st value from list added
    int tempval = val;
    tempval = get_new_rand( tempval);   // the second random value calculated here 
    boolean ifcontains = randval.contains( tempval ) ;

    while ( ifcontains != true )
    {   randval.add( tempval ); 
        tempval = get_new_rand( tempval); // calculate next value based on tempval
        ifcontains = randval.contains( tempval ) ;
    } 

    int idx = randval.indexOf( tempval ) ;
    return idx+1 ; // to compensate the ZERO offset 
shatseli     2020-02-15 06:54:47

Hi Rodion, Pls ignore this thread: I solved it correctly now ! ( I've found that used the wrong method. after correction all starts working like the swiss clock ;-) ) Thank you for the challenge and have a nice weekend !

Rodion (admin)     2020-02-17 06:59:39
User avatar

Hi Eli!

Pls ignore this thread: I solved it correctly now !

Ha-ha! I confess that this time I intentionally decided to allow some delay - suspecting that you probably will figure this out (which I believe is always more useful), so I'm happy I guessed right :)

BTW, congratulations on reaching the next rank / color!

Please login and solve 5 problems to be able to post at forum