binHex.py

from random import randint
def boxStringTupleList():
    bstl = []
    n = 0
    for l in range(5):
        for m in range(5):
            bstl.append((n, str(l) + str(m)))
            n +=1
    return bstl
  
boxStringTupleList()
0.2s
Python
[(0, '00'), (1, '01'), (2, '02'), (3, '03'), (4, '04'), (5, '10'), (6, '11'), (7, '12'), (8, '13'), (9, '14'), (10, '20'), (11, '21'), (12, '22'), (13, '23'), (14, '24'), (15, '30'), (16, '31'), (17, '32'), (18, '33'), (19, '34'), (20, '40'), (21, '41'), ...]
def shuffle(l):
    count = 0
    randomList = []
    for i in range(0, (len(l))):
        number = randint(0, (len(l)-1))
        randomList.append(l.pop(number))
        count +=1
    return randomList
  
randomBoxStringTupleList = shuffle(boxStringTupleList())
0.2s
Python
def binHexNums():
    hexList = []
    binList = []
    binHexList = []
    aList = []
    hexString = '0x'
    secondDigit = ['0', 'a', 'f']
    num = 0
    count = 0
    for j in range(len(secondDigit)):
        for i in range(16):
            firstDigit = str(hex(i))
            firstDigit = firstDigit[-1]
            hexList.append(hexString + secondDigit[j] + firstDigit)
            if secondDigit[j] == 'a' or secondDigit[j] == 'A':
                num = 160
            elif secondDigit[j] == 'b' or secondDigit[j] == 'B':
                num = 176
            elif secondDigit[j] == 'c' or secondDigit[j] == 'C':
                num = 192
            elif secondDigit[j] == 'd' or secondDigit[j] == 'D':
                num = 208
            elif secondDigit[j] == 'e' or secondDigit[j] == 'E':
                num = 224
            elif secondDigit[j] == 'f' or secondDigit[j] == 'F':
                num = 240
            else:
                num = 16*int(secondDigit[j])
            number = num + i
     
            if secondDigit[j] == '0':
                binString = bin(number)
                while len(binString) != 6:
                    binString = binString[:2] + '0' + binString[2:]
                binaryNum = '0b0000 ' + binString[2:]
            else:
                binaryNum = bin(number)
                binaryNum = binaryNum[:6] + ' ' + binaryNum[6:]
            binList.append(binaryNum)
            aList.append([hexList[j*16 + i], binList[j* 16 + i], number])
            binHexList.append(aList[count])
            count +=1
    #pick twelve pairs for the board
    nextList = []
    for i in range(12):
        randNumber = randint(0, (len(binHexList)-1))
        nextList.append(binHexList.pop(randNumber))
    # now add WildCard
    wildCardNum = randint(0, 23)
    finalTupleList = []
    counter = 0
    done = 0
    for i in range(12):
        if i == int(wildCardNum/2) and done == 0 or i == (int(wildCardNum/2) + 1) and done == 0:
            finalTupleList.append((randomBoxStringTupleList[counter][0], randomBoxStringTupleList[counter][1], 'Wild Card', 1000))
        
            counter +=1
            done = 1
        finalTupleList.append((randomBoxStringTupleList[counter][0], randomBoxStringTupleList[counter][1], nextList[i][0], nextList[i][2]))
        counter +=1
        finalTupleList.append((randomBoxStringTupleList[counter][0], randomBoxStringTupleList[counter][1], nextList[i][1], nextList[i][2]))
        counter +=1
    finalTupleList.sort()
    return finalTupleList
          
binHexNums()
0.2s
Python
[(0, '00', 'Wild Card', 1000), (1, '01', '0b0000 0000', 0), (2, '02', '0b1111 0000', 240), (3, '03', '0x0d', 13), (4, '04', '0b0000 0111', 7), (5, '10', '0xaf', 175), (6, '11', '0xf5', 245), (7, '12', '0b1010 1100', 172), (8, '13', '0b1010 1111', 175), (9, '14', '0x07', 7), (10, '20', '0x0f', 15), (11, '21', '0b0000 1111', 15), (12, '22', '0b1010 0001', 161), (13, '23', '0xf1', 241), (14, '24', '0b1111 0111', 247), (15, '30', '0xac', 172), (16, '31', '0b0000 1101', 13), (17, '32', '0xf0', 240), (18, '33', '0xf7', 247), (19, '34', '0b0000 1010', 10), (20, '40', '0x0a', 10), (21, '41', '0xa1', 161), ...]
0.2s
Python

Runtimes (1)