-1

import random x=0

MainArray = [1,2,3,4,5,6,7,8,9,10,11]

MoveArray0 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray1 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray2 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray3 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray4 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray5 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray6 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray7 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray8 = [2,1,3,4,5,6,7,8,9,10,11]
MoveArray9 = [2,1,3,4,5,6,7,8,9,10,11]
sorted = Falsewhile sorted == False:
 random.shuffle(MoveArray0)
 random.shuffle(MoveArray1)
 random.shuffle(MoveArray2)
 random.shuffle(MoveArray3)
 random.shuffle(MoveArray4)
 random.shuffle(MoveArray5)
 random.shuffle(MoveArray6)
 random.shuffle(MoveArray7)
 random.shuffle(MoveArray8)
 random.shuffle(MoveArray9)
  x=x+1
if MainArray == MoveArray0 or MainArray == MoveArray1 or 
MainArray == MoveArray2 or MainArray == MoveArray3 or MainArray == MoveArray4 or MainArray == MoveArray5 or MainArray == MoveArray6 or MainArray == MoveArray7 or MainArray == MoveArray8 or MainArray == MoveArray9:
sorted = True

else: print(x) print(MoveArray0) print(MoveArray1) print(MoveArray2) print(MoveArray3) print(MoveArray4) print(MoveArray5) print(MoveArray6) print(MoveArray7) print(MoveArray8) print(MoveArray9)

have this in a bogo sort program and want to know if theres anyway to make it shorter

havent treid anything else as I'm unsure as im new to python

  • 1
    https://stackabuse.com/python-check-if-array-or-list-contains-element-or-value/ does this help? im not a python expert, but maybe create an array of `MoveArrays = [MoveArray0, MoveArray1, ...]` and see if `if MainArray in MoveArrays` helps? – Isaac Mar 06 '23 at 02:18
  • 1
    If you have variables named in the form of `variable#`, you are likely using the wrong data structure entirely. If this is not immediately apparent to you, you likely need to brush up on foundational data structures concepts. – esqew Mar 06 '23 at 02:18
  • 1
    to extend what @esqew said, maybe create MoveArray directly: `MoveArray = [[], [], []]` etc: https://www.educba.com/multidimensional-array-in-python/ – Isaac Mar 06 '23 at 02:19
  • To do the comparison, make a set (or list) of the lists, and check whether `MainArray` is `in` that - see the linked duplicate. To make multiple arrays, use a loop or a comprehension to create the aforementioned set/list. Please read [ask] and note that this is **not a discussion forum** and we expect **one** question at a time, and we cannot teach or tutor you - we can only answer questions, which requires you to have something **specific** in mind. – Karl Knechtel Mar 06 '23 at 02:45

1 Answers1

1

Well, that is a strange project. Can I suggest that you do not need to copy MoveArray 10 times?

import random
x = 0
MainArray = [1,2,3,4,5,6,7,8,9,10,11]

MoveArray = [2,1,3,4,5,6,7,8,9,10,11]
sorted = False
while sorted == False:
    random.shuffle(MoveArray)

    x=x+1
    if MainArray == MoveArray:
        sorted = True
        break
    else: 
        print(x)
        print(MoveArray)