Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

#Bash, 85

Bash, 85

This doesn't compete golf-wise with @xnor's magic polynomial. But I think this is another interesting way to calculate the answer:

g(){
((d[1ドル2ドル]))||{
d[1ドル2ドル]=3ドル
g 2ドル 1ドル $[7-3ドル]
g 2ドル 3ドル 1ドル
}
}
g 1 2 3
echo ${d[1ドル2ドル]}

Specifically we know the the following about dice:

  • If the left face is 1 and the right face is 2, then the top face is 3
  • Rotation around opposite vertices by 120° gives some more triples of face values. E.g we rotate {l=1,r=2,t=3} once we get {l=2,r=3,t=1} and rotating again we get {l=3,r=1,t=2}
  • The sum of opposite faces is always 7

Combining the above recursively (using {1,2,3} hardcoded as a starting point), we can generate the entire mapping of {l,r}->t for all possible values. This answer defines a recursive function g() that populates a full array such that d[lr]=t. The recursive function is initially called with {1,2,3} and recurses all over the whole cube until there are no more array elements that have not been set. The function recurses into itself in two ways:

  • with l and r swapped and t subtracted from 7 (opposite faces)
  • with {l,r,t} rotated to {r,t,l}

It then does a simple array lookup of the values required.

#Bash, 85

This doesn't compete golf-wise with @xnor's magic polynomial. But I think this is another interesting way to calculate the answer:

g(){
((d[1ドル2ドル]))||{
d[1ドル2ドル]=3ドル
g 2ドル 1ドル $[7-3ドル]
g 2ドル 3ドル 1ドル
}
}
g 1 2 3
echo ${d[1ドル2ドル]}

Specifically we know the the following about dice:

  • If the left face is 1 and the right face is 2, then the top face is 3
  • Rotation around opposite vertices by 120° gives some more triples of face values. E.g we rotate {l=1,r=2,t=3} once we get {l=2,r=3,t=1} and rotating again we get {l=3,r=1,t=2}
  • The sum of opposite faces is always 7

Combining the above recursively (using {1,2,3} hardcoded as a starting point), we can generate the entire mapping of {l,r}->t for all possible values. This answer defines a recursive function g() that populates a full array such that d[lr]=t. The recursive function is initially called with {1,2,3} and recurses all over the whole cube until there are no more array elements that have not been set. The function recurses into itself in two ways:

  • with l and r swapped and t subtracted from 7 (opposite faces)
  • with {l,r,t} rotated to {r,t,l}

It then does a simple array lookup of the values required.

Bash, 85

This doesn't compete golf-wise with @xnor's magic polynomial. But I think this is another interesting way to calculate the answer:

g(){
((d[1ドル2ドル]))||{
d[1ドル2ドル]=3ドル
g 2ドル 1ドル $[7-3ドル]
g 2ドル 3ドル 1ドル
}
}
g 1 2 3
echo ${d[1ドル2ドル]}

Specifically we know the the following about dice:

  • If the left face is 1 and the right face is 2, then the top face is 3
  • Rotation around opposite vertices by 120° gives some more triples of face values. E.g we rotate {l=1,r=2,t=3} once we get {l=2,r=3,t=1} and rotating again we get {l=3,r=1,t=2}
  • The sum of opposite faces is always 7

Combining the above recursively (using {1,2,3} hardcoded as a starting point), we can generate the entire mapping of {l,r}->t for all possible values. This answer defines a recursive function g() that populates a full array such that d[lr]=t. The recursive function is initially called with {1,2,3} and recurses all over the whole cube until there are no more array elements that have not been set. The function recurses into itself in two ways:

  • with l and r swapped and t subtracted from 7 (opposite faces)
  • with {l,r,t} rotated to {r,t,l}

It then does a simple array lookup of the values required.

Source Link
Digital Trauma
  • 73.7k
  • 10
  • 116
  • 268

#Bash, 85

This doesn't compete golf-wise with @xnor's magic polynomial. But I think this is another interesting way to calculate the answer:

g(){
((d[1ドル2ドル]))||{
d[1ドル2ドル]=3ドル
g 2ドル 1ドル $[7-3ドル]
g 2ドル 3ドル 1ドル
}
}
g 1 2 3
echo ${d[1ドル2ドル]}

Specifically we know the the following about dice:

  • If the left face is 1 and the right face is 2, then the top face is 3
  • Rotation around opposite vertices by 120° gives some more triples of face values. E.g we rotate {l=1,r=2,t=3} once we get {l=2,r=3,t=1} and rotating again we get {l=3,r=1,t=2}
  • The sum of opposite faces is always 7

Combining the above recursively (using {1,2,3} hardcoded as a starting point), we can generate the entire mapping of {l,r}->t for all possible values. This answer defines a recursive function g() that populates a full array such that d[lr]=t. The recursive function is initially called with {1,2,3} and recurses all over the whole cube until there are no more array elements that have not been set. The function recurses into itself in two ways:

  • with l and r swapped and t subtracted from 7 (opposite faces)
  • with {l,r,t} rotated to {r,t,l}

It then does a simple array lookup of the values required.

AltStyle によって変換されたページ (->オリジナル) /