Skip to content

Instantly share code, notes, and snippets.

@cgbeutler
Created August 24, 2024 23:07
Show Gist options
  • Save cgbeutler/2c810a4982538b01b9ab4e292ed4fad2 to your computer and use it in GitHub Desktop.
Save cgbeutler/2c810a4982538b01b9ab4e292ed4fad2 to your computer and use it in GitHub Desktop.
from math import factorial
from sympy.utilities.iterables import multiset_permutations
print("Searching...")
# Numerically balanced dice
# To calculate:
# 1. Find the average value of a face
# 2. Multiply that average by the number of faces touching a vert.
# The result is the value each vert should have.
# 3. The d30 has 2 types of verts. Face averages come to a ##.5 value, so
# normally some vertices have to be higher and others lower than that.
# For a d30 that uses: [0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,7,7,7,8,8,9]
# Average face value: 4.5
# 32 verts total. 20 with 3-faces. 12 with 5-faces.
# 3-faces need 13.5 -- Thats 10x 13s and 10x 14s
# 5-faces need 22.5 -- Thats 6x 22s and 6x 23s
# We will use the following mappings.
# Negatives used for "inverse" side. Vertices labeled with their desired sums.
# -4 E_-"\ 23 /`-_F -2
# _-" \ / `-_
# -4 \ 11 \/ 9 /
# D_-``-_ \ _-``-_ / _-``-_A -2
# 22_-" 12 `-_ \_-" `-_/ _-" 8 `-_ 22
#-7 /`-_ _-"\ 22/`-_ 10 _-"\23 /`-_ _-"
# C/ `-__-" \ / `-__-" \ / `-__-"B -14
# / 14 /\ 13 \/ 0 /\ 6 \/ 7 /
# `-_ / \ _-"`-_ / \ _-"`-_ /C -14
# B`-_/ \_-" 1 `-_/ \_-" 5 `-_/
# -8 23/`-_ _-"\22 `-_ _-"\23
# -8 A/ `-__-" \ `-__-" \D -12
# / 2 /\ 3 \ \ 4 \
# `-_ / \ _-" \ _-"
# -9 F`-_/ \_-" 22 \_-"E -11
triplets = [ [11,12,-4], [9,10,11], [8,9,-2], [12,13,14], [0,1,13], [0,6,10], [5,6,7], [7,8,-14], [1,2,3], [3,4,5] ]
pentlets = [ [0,10,11,12,13], [6,7,8,9,10], [0,1,3,5,6], [4,5,7,-12,-14], [1,2,13,14,-8], [2,3,4,-9,-11] ]
pentsums = [ 22, 23, 22, 23, 23, 22 ]
# Permute half of the die values, skipping the first, as thats always 0. We will permute inverting them later.
face_bag = [1,1,2,2,2,3,3,3,3,4,4,4,4,4] #len 14
flip_bag = [0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1]
count = 0
try:
for raw_face_perm in multiset_permutations(face_bag):
# Pumutations of flipping bits
for flip_perm in multiset_permutations(flip_bag,14):
count += 1
face_perm = [0, *raw_face_perm]
# Flip the same spots as the bits
for i in range(len(flip_perm)):
if flip_perm[i]: face_perm[i+1] = 9 - face_perm[i+1]
# Should sum 13 or 14
n13 = 0
n14 = 0
fail = False
for trips in triplets:
sum = 0
for t_face in trips:
sum += face_perm[t_face] if t_face >= 0 else 9 - face_perm[abs(t_face)]
if sum == 13: n13 += 1
elif sum == 14: n14 += 1
else:
fail = True
break
if n13 > 10 or n14 > 10:
fail = True
break
if fail: continue
fail = False
for (pent_i, pents) in enumerate(pentlets):
sum = 0
for p_face in pents:
sum += face_perm[p_face] if p_face >= 0 else 9 - face_perm[abs(p_face)]
if sum != pentsums[pent_i]:
fail = True
break
if fail: continue
print( "Found %s" %[face_perm] )
except KeyboardInterrupt:
print("Interrupt")
expected = (factorial(14) / (factorial(2)*factorial(3)*factorial(4)*factorial(5))) * (factorial(14)/(factorial(8)*factorial(8)))
print( "Got to %s\n of %s\n (%s %%)" %(count, expected, (count/expected*100)) )
# Full die unwrap diagram
# _-"\ _-"\ _-"\ _-"\ _-"\
# _-" \ _-" \ _-" \ _-" \ _-" \
# \ \ \ \ \ \ \ \ \ \
# \ _-"`-_ \ _-"`-_ \ _-"`-_ \ _-"`-_ \ _-"`-_
# \_-" `-_ \_-" `-_ \_-" `-_ \_-" `-_ \_-" `-_
# /`-_ _-"\ /`-_ _-"\ /`-_ _-"\ /`-_ _-"\ /`-_ _-"\
# / `-__-" \ / `-__-" \ / `-__-" \ / `-__-" \ / `-__-" \
# / /\ \/ /\ \/ /\ \/ /\ \/ /\ \
# `-_ / \ _-"`-_ / \ _-"`-_ / \ _-"`-_ / \ _-"`-_ / \ _-"`-_
# `-_/ \_-" `-_/ \_-" `-_/ \_-" `-_/ \_-" `-_/ \_-" `-_
# /`-_ _-" /`-_ _-" /`-_ _-" /`-_ _-" /`-_ _-"
# / `-__-" / `-__-" / `-__-" / `-__-" / `-__-"
# / / / / / / / / / /
# `-_ / `-_ / `-_ / `-_ / `-_ /
# `-_/ `-_/ `-_/ `-_/ `-_/
# Discovered results
#[0, 8, 1, 4, 6, 3, 7, 4, 3, 2, 7, 5, 5, 5, 3]
#[0, 8, 1, 5, 5, 3, 6, 5, 2, 3, 7, 4, 6, 5, 2]
#[0, 8, 2, 3, 6, 4, 7, 3, 5, 1, 7, 6, 4, 5, 4] This one looks promising
# E_-"\ 23 /`-_F
# _-" \ / `-_
# \ 6 \/ 1 /
# D_-13-_ \ _-14-_ / _-13-_A
# 22_-" 4 `-_ \_-" `-_/ _-" 5 `-_ 22
# /`-_ _-"\ 22/`-_ 7 _-"\23 /`-_ _-"
# C/ `-13-" \ / `-14-" \ / `-13-"B
# / 4 /\ 5 \/ 0 /\ 7 \/ 3 /
# `-_ / \ _-13-_ / \ _-14-_ /C
# B`-_/ \_-" 8 `-_/ \_-" 4 `-_/
# 4 23/`-_ _-"\22 `-_ _-"\23
# A/ `-13-" \ `-13-" \D
# / 2 /\ 3 \ \ 6 \
# 14`-_ / \ _-" \ _-"
# F`-_/ \_-" 22 \_-"E
#[0, 8, 3, 2, 5, 6, 6, 2, 5, 2, 8, 4, 5, 5, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment