none
Shuffle the list RRS feed

  • Question

  • Hi,

    i have two list

    1) apple = 10, orange = 10, grapes = 5, mango = 13, peach = 20

    i want the shuffle in a way that no fruit has to repeat twice in the list

    like>> apple,orange,grape,apple,peach,grape,mango   or any order

    2) Ball = 45, bat = 5, cake = 8, net = 7, rocket = 6

    here in shuffling ball can appear twice but not always, and shuffling should not have other object repeat twice also it should

    not have the last object again in the next shuffle. 

    like >> ball,bat,ball,ball,cake,net,ball,rocket   ----> okie

    ball,bat,ball,ball,bat,net,ball,rocket   ----> bat comes again in 2nd and 5th it shuld not come, ball can some since it have more count

    please help me how we can archive the shuffling

    Thanks


    • Edited by alex_prvn Saturday, July 28, 2018 11:51 AM
    Saturday, July 28, 2018 11:50 AM

All replies

  • This is obviously a class assignment that is intended to help you learn how to program. The best way to help you is to support your effort to do it yourself. You should do as much as you can and then ask specific questions instead of hoping that we will do all of it.

    The problem seems to be the same as if a deck of cards is shuffled; there can never be more than one existence of each card.

    Here is a hint. You can create a from-list and a to-list, or you could call them an unshuffled list and shuffled list. The program can randomly pick an item from the unshuffled and remove it from that list and add it to the shuffled list. So try to write a program to do that and show us what you have and then we can help with specific problems.



    Sam Hobbs
    SimpleSamples.Info


    Saturday, July 28, 2018 3:28 PM
  • I would help doing myself, but Simples Samples-san gave a fair and important reply.
    So there's a help for your brain.

    count the number of items of the list.
    search how to implement random number.
    then write a condition before to skip each random number that has been used,

    If that doesn't help, just say it.

    1) apple = 10, orange = 10, grapes = 5, mango = 13, peach = 20

    IDK if those number are the remaining or the amount of each item.
    Can you make a illustration or explain in more details?
    Should those numbers and the fruit be linked? Like <fruitName,amoutOrSomething>?
    because this output of yours only shows their name "like>> apple,orange,grape,apple,peach,grape,mango"

    And btw: this list output of yours repeats apple and grape, is that right?
    This shuffle is only in the output or you need a new list shuffled? 

    Explain the text above in more detail, please.
    I didn't understand nothing of it.

    "
    not have the last object again in the next shuffle. 

    like >> ball,bat,ball,ball,cake,net,ball,rocket   ----> okie

    ball,bat,ball,ball,bat,net,ball,rocket   ----> bat comes again in 2nd and 5th it shuld not come, ball can some since it have more count

    "


    BP-LP 2005/2016 @ll rights reserved



    Saturday, July 28, 2018 9:25 PM
  • Hi Thanks for the reply,

    apple = 10, orange = 10, grapes = 5, mango = 13, peach = 20 means

    sting[] _list ={apple,apple,apple,apple,apple,apple,apple,apple,apple,apple,orange ,orange ,orange ,orange ,orange ,orange ,orange ,orange ,orange ,orange ,grapes ,grapes ,grapes ,grapes ,grapes ,mango ,mango ,mango ,mango,mango,mango,mango,mango,mango,mango ,mango ,mango ,mango ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach ,peach };

    forget the space between text.  above is the simple order.

    we have to shuffle in such a way that no fruit should come twice next in list 

    senario 2, Ball = 45, bat = 5, cake = 8, net = 7, rocket = 6

    List<string> or array have about count of strings like 45 "Ball", 5 "Bat"

    when we shuffle there is a accumulation of Ball in the list in last. since Ball have more(50% more than) when comparing the next largest count in list that is cake of 8.

    we can have two Ball next not 3 balls like => ball,bat,ball,ball,bat,net,ball,rocket

    not like=> ball,bat,ball,ball,ball,bat,net,ball,rocket

    when we shuffle end of the list is filled up with Ball or if we insert between some time it end up looping(if condition for no 3 ball) or 3 balls like above

    Thanks

    Friday, August 10, 2018 6:13 AM