This isn't exactly what you want, but it shows the idea of what it might look like in Python.
Python is going to seem strange coming from (line-numbered) basic. But it's one of the easiest modern language to learn and it's very powerful (with it's standard library and other libraries). It will be a bit of a journey, but well worth it if you have any interest in or need of programming.
In a Python program, the indentation is critical, so be careful with moving stuff around.
To get python: https://www.python.org/ Python 3.4.0 is probably best for you. Documentation: https://docs.python.org/3/
# A hash tag indicates a comment to the end of the line.
def increment(dice): # define a function (aka, subroutine)
dice[0] += 1
if dice[0] > 6:
dice[0] = 1
dice[1] += 1
if dice[1] > 6:
dice[1] = 1
dice[2] += 1
if dice[2] > 6:
dice[2] = 1
dice[3] += 1
if dice[3] > 6:
dice[3] = 1
dice[4] += 1
if dice[4] > 6:
dice[4] = 1
dice[5] += 1
if dice[5] > 6:
dice[5] = 1
return False # return False when done
return True
def count_pips(dice):
counts = [0, 0, 0, 0, 0, 0]
for x in dice:
counts[x-1] += 1 # x-1 because of 0-based indices
return counts
def analyze_counts(counts):
stats = [] # will hold number of doubles, number of triples, etc.
for i in range(2, 7):
stats.append(counts.count(i))
return stats
# Note that list indices are 0-based
# so indices will go from 0 to 5 for 6 elements.
dice = [1, 1, 1, 1, 1, 1]
counts = count_pips(dice)
stats = analyze_counts(counts)
print dice, stats
while increment(dice):
counts = count_pips(dice)
stats = analyze_counts(counts)
print(dice, stats)
If you can describe more specifically exactly what you're trying to do I can maybe fix it up a little.
Some explanation of the code:
dice
is a list whose elements are incremented like an odometer (with values 1 to 6) through all the combinations from 1,1,1,1,1,1 to 6,6,6,6,6,6. (But you knew that!)
counts
is a list that is filled with counts of the number of 1's, 2's, etc that are in dice
.
stats
is a list that is filled with the number of 2's, 3's, etc in count
. Lists have functions associated with them, such as count
(which is coincidentally named similar to our variable counts
). The count
function returns the number of elements in the given list with the given value.
Also note that the line:
for i in range(2, 7):
is a loop where i
takes on values from 2 to 6 (one less than the second number, which might seem a little strange, but that's the way it works).