Skip to main content
added 31 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields a positive integer (truthy) if possible or \$0\$ (falsey) if not.

Try it online! Or see the test-suite.

How?

First, this constructs a list of all permutations of the indices of \$S\$ which do not decrease after their first increase.

e.g. for \$S\$ of length four:

[1, 2, 3, 4] [2, 1, 3, 4] [3, 1, 2, 4] [3, 2, 1, 4] [4, 1, 2, 3] [4, 2, 1, 3] [4, 3, 1, 2] [4, 3, 2, 1] 

It then uses these to index into the deck, \$\sigma\$, to construct all the possible signs and counts the occurrences of the sign, \$S\$.

JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) J - range of length (S) -> [1,2,3,...,length(S)] Œ! - all permutations Ƈ - filter keep those for which: $ - last two links as a monad: Ɲ - for neighbouring pairs: < - less than? Ƒ - is invariant under?: Ṣ - sort ị - index into (D) (vectorises) ⁸ - chain's left argument = S ċ - count occurrences 

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields a positive integer (truthy) if possible or \$0\$ (falsey) if not.

Try it online! Or see the test-suite.

How?

JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) J - range of length (S) -> [1,2,3,...,length(S)] Œ! - all permutations Ƈ - filter keep those for which: $ - last two links as a monad: Ɲ - for neighbouring pairs: < - less than? Ƒ - is invariant under?: Ṣ - sort ị - index into (D) (vectorises) ⁸ - chain's left argument = S ċ - count occurrences 

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields a positive integer (truthy) if possible or \$0\$ (falsey) if not.

Try it online! Or see the test-suite.

How?

First, this constructs a list of all permutations of the indices of \$S\$ which do not decrease after their first increase.

e.g. for \$S\$ of length four:

[1, 2, 3, 4] [2, 1, 3, 4] [3, 1, 2, 4] [3, 2, 1, 4] [4, 1, 2, 3] [4, 2, 1, 3] [4, 3, 1, 2] [4, 3, 2, 1] 

It then uses these to index into the deck, \$\sigma\$, to construct all the possible signs and counts the occurrences of the sign, \$S\$.

JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) J - range of length (S) -> [1,2,3,...,length(S)] Œ! - all permutations Ƈ - filter keep those for which: $ - last two links as a monad: Ɲ - for neighbouring pairs: < - less than? Ƒ - is invariant under?: Ṣ - sort ị - index into (D) (vectorises) ⁸ - chain's left argument = S ċ - count occurrences 
added 31 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields a positive integer \$1\$(truthy) if possible or \$0\$ (falsey) if not.

Try it online! Or see the test-suite.

How?

JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) J - range of length (S) -> [1,2,3,...,length(S)] Œ! - all permutations Ƈ - filter keep those for which: $ - last two links as a monad: Ɲ - for neighbouring pairs: < - less than? Ƒ - is invariant under?: Ṣ - sort ị - index into (D) (vectorises) ⁸ - chain's left argument = S ċ - count occurrences 

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields \$1\$ if possible or \$0\$ if not.

Try it online! Or see the test-suite.

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields a positive integer (truthy) if possible or \$0\$ (falsey) if not.

Try it online! Or see the test-suite.

How?

JŒ!<ƝṢƑ$Ƈịċ⁸ - Link: list of characters S, list of characters D (sigma) J - range of length (S) -> [1,2,3,...,length(S)] Œ! - all permutations Ƈ - filter keep those for which: $ - last two links as a monad: Ɲ - for neighbouring pairs: < - less than? Ƒ - is invariant under?: Ṣ - sort ị - index into (D) (vectorises) ⁸ - chain's left argument = S ċ - count occurrences 
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 12 bytes

Employs the inverse test of a post by pxeger - here.

JŒ!<ƝṢƑ$Ƈịċ⁸ 

A dyadic Link that accepts the sign, \$S\$, on the left and the deck of letters, \$\sigma\$, on the right and yields \$1\$ if possible or \$0\$ if not.

Try it online! Or see the test-suite.