8 Replies - 196 Views - Last Post: 26 May 2020 - 01:33 PM Rate Topic: -----

#1 MoSalaholic11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-May 20

How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 10:58 AM

So as part of an assignment I have to implement Fisher-Yates Shuffle and a 7-Time Riffle Shuffle. I didn't have any problems implementing the Fisher-Yates Shuffle... found it quite easy and works fine. However, when implementing the 7-Time Riffle Shuffle algorithm, the shuffle is not working. I am not sure if I am doing something wrong. This is my code.

class RiffleShuffle : Shuffle 
{ 
   private int mid; 
   public void SuffleSequence(int[] rubikCubeArray) 
   {
      Random r = new Random();
      int i = mid; 
      int j = rubikCubeArray.Length - 1; 
      while (i <= 7) 
      {
        int temp = rubikCubeArray[i]; 
        rubikCubeArray[i--] = rubikCubeArray[j];
        rubikCubeArray[j--] = temp; 
       
      } 
   }
  }
}
:code:

Any help would be appreciated alot, because I would be able to complete the rest of the task! Thank you

This post has been edited by modi123_1: 26 May 2020 - 11:10 AM
Reason for edit:: In the future please use the [code] tags in the editor.


Is This A Good Question/Topic? 0
  • +

Replies To: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 11:10 AM

Quote

the shuffle is not working.

Explain this more. In what way is it not working? What is your input? What is the output? What are you expecting the output to be? Are there errors?
Was This Post Helpful? 0
  • +
  • -

#3 MoSalaholic11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-May 20

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 11:19 AM

View Postmodi123_1, on 26 May 2020 - 11:10 AM, said:

Quote

the shuffle is not working.

Explain this more. In what way is it not working? What is your input? What is the output? What are you expecting the output to be? Are there errors?

No errors are shown, however the Fisher-Yates shuffle is working perfectly fine, however the Riffle Shuffle is not. And the problem is somewhere in the method of the Riffle Shuffle, and I don't know what the problem is. ://>
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 11:33 AM

How are you aware the riffle-shuffle is not working correctly?
Was This Post Helpful? 0
  • +
  • -

#5 MoSalaholic11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-May 20

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 11:45 AM

View Postmodi123_1, on 26 May 2020 - 11:33 AM, said:

How are you aware the riffle-shuffle is not working correctly?

That's because when I checked the RUbik Cube sequence, the Fisher-Yates shuffle worked correctly, but the FIsher-Yates shuffle remained the same without even actually shuffling the sequence.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 12:12 PM

That didn't quite make sense, but ok.

When you put a breakpoint in the function do you see the array being shuffled? Is it just an issue of you returning the shuffled array from the method?
Was This Post Helpful? 0
  • +
  • -

#7 MoSalaholic11   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 26-May 20

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 01:09 PM

View Postmodi123_1, on 26 May 2020 - 12:12 PM, said:

That didn't quite make sense, but ok.

When you put a breakpoint in the function do you see the array being shuffled? Is it just an issue of you returning the shuffled array from the method?


What I am trying to say is that there is no errors. However, the Riffle Shuffle method is not implemented correctly and I am not sure what to do really.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15797
  • View blog
  • Posts: 63,297
  • Joined: 12-June 08

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 01:13 PM

Mkay.. so you don't return anything from the method. I am not sure if that is by design or by accident.

You also do not use the randomize variable either.

Also seen here.
Was This Post Helpful? 1
  • +
  • -

#9 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7453
  • View blog
  • Posts: 25,095
  • Joined: 05-May 12

Re: How to correctly implement 7-Time Riffle Shuffle of a Rubik Cube in C#

Posted 26 May 2020 - 01:33 PM

Are you sure you are even using the code that you posted in your original post? If so, then you should have been getting an exception when i becomes negative and you start using a negative index into your array.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1