Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Heath DiCiphering dice. Determine sums possible
__author__ = 'johnsommer'
# url for description of the dice and unique properties
# http://www.creativecrafthouse.com/index.php?main_page=product_info&products_id=824
d = list(());
# list of Heath's dice
d.append([483, 285, 780, 186, 384, 681]);
d.append([642, 147, 840, 741, 543, 345]);
d.append([558, 855, 657, 459, 954, 756]);
d.append([168, 663, 960, 366, 564, 267]);
d.append([971, 377, 179, 872, 773, 278]);
dice = list(());
totals = list();
totals_sorted = list();
# Find all possible totals of 5 dice when rolling them
for i1 in d[0]:
for i2 in d[1]:
for i3 in d[2]:
for i4 in d[3]:
for i5 in d[4]:
dice.append ([i1,i2,i3,i4,i5, i1+i2+i3+i4+i5]);
totals.append (i1+i2+i3+i4+i5);
# print(i1,i2,i3,i4,i5, i1+i2+i3+i4+i5);
# done
totals_sorted = sorted(totals);
dice.sort(key=lambda e: e[5]);
# get a list of unique sums
totals_set = set(totals_sorted);
# hilow list is to represent the list of unique sum using the 1st 2 digits and last 2 digits as pairs.
# Arrange the ser of pairs with the highest of the pairs first.
hilow = list();
for t1 in totals_set:
first2 = int(str(t1)[0:2]);
last2 = int(str(t1)[2:4]);
if (first2 > last2):
hl = first2*100 + last2;
else:
hl = last2*100 + first2;
hilow.append (hl);
# Create a unique list
hilow = set(hilow);
# print( len(dice), len(totals), dice[0], totals[0],totals_sorted[0], len(totals_set), len(hilow));
print('5 unique set of dice');
for i in d:
print(i);
print(len(dice));
print('Total number of possible dice rolls', len(dice));
print('Number of unique sums = ', len(totals_set));
print('List of unique sums = ', sorted(totals_set));
print('Number of unique sums using first 2 digits and last 2 - highest of pair first', len(hilow));
print('Unique sums using first 2 digits and last 2 - highest of pair first', sorted(hilow));
# print(sorted(totals_set));
# print(hilow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment