Skip to main content
deleted 39 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

BQN, 9 bytes

¯12>-˜´∘∨

Try it at BQN online REPL

Outputs 0 if the dice are 6-sided, 1 if the alien is cheating.

We calculate the highest die roll using a single fold (or reduce in some languages) of a "minus" operation across the 3 sums-of-2-rolls in increasing order.
Consider initial die rolls of s, m and l, where l is the (possibly non-unique) largest, and s is the smallest. Then, the sums-of-2-rolls, in increasing order, are: s+m, s+l, m+l.
Folding "minus" across this yields (s+m minus s+l) minus m+l = m-l - (m+l) = -2l. So we just need to check whether the result is less than minus 12: if it is, then l was greater than 6 and the alien was cheating.

         ∨   # sort the input
        ∘    # and use that to
     -˜´     # fold 'subtracted from' from the right
    -        # then negate the result
¯12>         # and check whether it's less than minus 12

This comes out 1 byte shorter than the "subtract the lowest value from half the sum of the input" approach (12<+´-2×⌊´ = 10 bytes in BQN: try it)

BQN, 9 bytes

¯12>-˜´∘∨

Try it at BQN online REPL

Outputs 0 if the dice are 6-sided, 1 if the alien is cheating.

We calculate the highest die roll using a single fold (or reduce in some languages) of a "minus" operation across the 3 sums-of-2-rolls in increasing order.
Consider initial die rolls of s, m and l, where l is the (possibly non-unique) largest, and s is the smallest. Then, the sums-of-2-rolls, in increasing order, are: s+m, s+l, m+l.
Folding "minus" across this yields (s+m minus s+l) minus m+l = m-l - (m+l) = -2l. So we just need to check whether the result is less than minus 12: if it is, then l was greater than 6 and the alien was cheating.

         ∨   # sort the input
        ∘    # and use that to
     -˜´     # fold 'subtracted from' from the right
    -        # then negate the result
¯12>         # and check whether it's less than minus 12

This comes out 1 byte shorter than the "subtract the lowest value from half the sum of the input" approach (12<+´-2×⌊´ = 10 bytes in BQN: try it)

BQN, 9 bytes

¯12>-˜´∘∨

Try it at BQN online REPL

Outputs 0 if the dice are 6-sided, 1 if the alien is cheating.

We calculate the highest die roll using a single fold (or reduce in some languages) of a "minus" operation across the 3 sums-of-2-rolls in increasing order.
Consider initial die rolls of s, m and l, where l is the (possibly non-unique) largest, and s is the smallest. Then, the sums-of-2-rolls, in increasing order, are: s+m, s+l, m+l.
Folding "minus" across this yields (s+m minus s+l) minus m+l = m-l - (m+l) = -2l. So we just need to check whether the result is less than minus 12: if it is, then l was greater than 6 and the alien was cheating.

         ∨   # sort the input
        ∘    # and use that to
     -˜´     # fold 'subtracted from' from the right
¯12>         # and check whether it's less than minus 12

This comes out 1 byte shorter than the "subtract the lowest value from half the sum of the input" approach (12<+´-2×⌊´ = 10 bytes in BQN: try it)

Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

BQN, 9 bytes

¯12>-˜´∘∨

Try it at BQN online REPL

Outputs 0 if the dice are 6-sided, 1 if the alien is cheating.

We calculate the highest die roll using a single fold (or reduce in some languages) of a "minus" operation across the 3 sums-of-2-rolls in increasing order.
Consider initial die rolls of s, m and l, where l is the (possibly non-unique) largest, and s is the smallest. Then, the sums-of-2-rolls, in increasing order, are: s+m, s+l, m+l.
Folding "minus" across this yields (s+m minus s+l) minus m+l = m-l - (m+l) = -2l. So we just need to check whether the result is less than minus 12: if it is, then l was greater than 6 and the alien was cheating.

         ∨   # sort the input
        ∘    # and use that to
     -˜´     # fold 'subtracted from' from the right
    -        # then negate the result
¯12>         # and check whether it's less than minus 12

This comes out 1 byte shorter than the "subtract the lowest value from half the sum of the input" approach (12<+´-2×⌊´ = 10 bytes in BQN: try it)