Post History
Dyalog APL, 19 bytes (with index origin zero) {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7} This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence A000920. \[ P_n = \frac{\mathsf{...
Answer
#3: Post edited
- # Dyalog APL, 19 bytes
- (with index origin zero)
- ```apl
- {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7}
- ```
- This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence [A000920](https://oeis.org/A000920).
- \[
- P_n = \frac{\mathsf{OEIS}_{\text{A000920}}(n)}{6^n}
- \]
- which is
- \[
- \frac {6!} {6^n} \left\lbrace {n \atop 6}\right\rbrace
- \]
- where $\left\lbrace{n\atop k}\right\rbrace$ are the [Stirling numbers of the second kind](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), which expand like this:
- \[
- \frac 1 {6^n} \sum_{i=0}^6 \left(-1\right)^{6-i} i^n \binom 6 i
- \]
- (where $\binom n k$ are [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient)) which simplifies to
- \[
- \sum_{i=0}^6 \left(-1\right)^i \binom 6 i\left(\frac i 6\right)^n
- \]
- Note that the $i=0$ term is zero, but it is useful for me because it means the first term of the alternate sum has a positive coefficient.
- Code explanation:
- * `⍳7` To the list of numbers 0 through 6, apply the following function:
- * `!∘6` $\binom 6 x$
- * `×` times
- * `6÷⍨⊢` $\frac x 6$
- * `⍵*⍨` to the power of $n$
- * `-/` and then take the alternate sum
- Kinda sad to see a bruteforce solution is smaller than the closed form, I'll try and find a language where this is even shorter :)
Side note: this seems to have some floating point error which means the results for $n \in \left\{ 3, 4, 5 ight\}$ aren't exactly zero but in the range of $10^{-16}$ with `⎕fr←647` and $10^{-34}$ with `⎕fr←1287`
- # Dyalog APL, 19 bytes
- (with index origin zero)
- ```apl
- {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7}
- ```
- This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence [A000920](https://oeis.org/A000920).
- \[
- P_n = \frac{\mathsf{OEIS}_{\text{A000920}}(n)}{6^n}
- \]
- which is
- \[
- \frac {6!} {6^n} \left\lbrace {n \atop 6}\right\rbrace
- \]
- where $\left\lbrace{n\atop k}\right\rbrace$ are the [Stirling numbers of the second kind](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), which expand like this:
- \[
- \frac 1 {6^n} \sum_{i=0}^6 \left(-1\right)^{6-i} i^n \binom 6 i
- \]
- (where $\binom n k$ are [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient)) which simplifies to
- \[
- \sum_{i=0}^6 \left(-1\right)^i \binom 6 i\left(\frac i 6\right)^n
- \]
- Note that the $i=0$ term is zero, but it is useful for me because it means the first term of the alternate sum has a positive coefficient.
- Code explanation:
- * `⍳7` To the list of numbers 0 through 6, apply the following function:
- * `!∘6` $\binom 6 x$
- * `×` times
- * `6÷⍨⊢` $\frac x 6$
- * `⍵*⍨` to the power of $n$
- * `-/` and then take the alternate sum
- Kinda sad to see a bruteforce solution is smaller than the closed form, I'll try and find a language where this is even shorter :)
- Side note: this seems to have some floating point error which means the results for $n \in \left\{ 3, 4, 5 ight\}$ aren't exactly zero but in the range of $10^{-16}$ with `⎕fr←647` and $10^{-34}$ with `⎕fr←1287`. either of these are both within the 6 decimal places of precision required, but just in case you cared about the pure computation, I think this is just error stacking up.
#2: Post edited
- # Dyalog APL, 19 bytes
- (with index origin zero)
- ```apl
- {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7}
- ```
- This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence [A000920](https://oeis.org/A000920).
- \[
- P_n = \frac{\mathsf{OEIS}_{\text{A000920}}(n)}{6^n}
- \]
- which is
- \[
- \frac {6!} {6^n} \left\lbrace {n \atop 6}\right\rbrace
- \]
- where $\left\lbrace{n\atop k}\right\rbrace$ are the [Stirling numbers of the second kind](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), which expand like this:
- \[
- \frac 1 {6^n} \sum_{i=0}^6 \left(-1\right)^{6-i} i^n \binom 6 i
- \]
- (where $\binom n k$ are [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient)) which simplifies to
- \[
- \sum_{i=0}^6 \left(-1\right)^i \binom 6 i\left(\frac i 6\right)^n
- \]
- Note that the $i=0$ term is zero, but it is useful for me because it means the first term of the alternate sum has a positive coefficient.
- Code explanation:
- * `⍳7` To the list of numbers 0 through 6, apply the following function:
- * `!∘6` $\binom 6 x$
- * `×` times
- * `6÷⍨⊢` $\frac x 6$
- * `⍵*⍨` to the power of $n$
- * `-/` and then take the alternate sum
Kinda sad to see a bruteforce solution is smaller than the closed form, I'll try and find a language where this is even shorter :)
- # Dyalog APL, 19 bytes
- (with index origin zero)
- ```apl
- {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7}
- ```
- This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence [A000920](https://oeis.org/A000920).
- \[
- P_n = \frac{\mathsf{OEIS}_{\text{A000920}}(n)}{6^n}
- \]
- which is
- \[
- \frac {6!} {6^n} \left\lbrace {n \atop 6}\right\rbrace
- \]
- where $\left\lbrace{n\atop k}\right\rbrace$ are the [Stirling numbers of the second kind](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), which expand like this:
- \[
- \frac 1 {6^n} \sum_{i=0}^6 \left(-1\right)^{6-i} i^n \binom 6 i
- \]
- (where $\binom n k$ are [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient)) which simplifies to
- \[
- \sum_{i=0}^6 \left(-1\right)^i \binom 6 i\left(\frac i 6\right)^n
- \]
- Note that the $i=0$ term is zero, but it is useful for me because it means the first term of the alternate sum has a positive coefficient.
- Code explanation:
- * `⍳7` To the list of numbers 0 through 6, apply the following function:
- * `!∘6` $\binom 6 x$
- * `×` times
- * `6÷⍨⊢` $\frac x 6$
- * `⍵*⍨` to the power of $n$
- * `-/` and then take the alternate sum
- Kinda sad to see a bruteforce solution is smaller than the closed form, I'll try and find a language where this is even shorter :)
- Side note: this seems to have some floating point error which means the results for $n \in \left\{ 3, 4, 5 \right\}$ aren't exactly zero but in the range of $10^{-16}$ with `⎕fr←647` and $10^{-34}$ with `⎕fr←1287`
#1: Initial revision
# Dyalog APL, 19 bytes (with index origin zero) ```apl {-/(!∘6×⍵*⍨6÷⍨⊢)⍳7} ``` This isn't bruteforce! The number of cases where all six faces appear are the OEIS sequence [A000920](https://oeis.org/A000920). \[ P_n = \frac{\mathsf{OEIS}_{\text{A000920}}(n)}{6^n} \] which is \[ \frac {6!} {6^n} \left\lbrace {n \atop 6}\right\rbrace \] where $\left\lbrace{n\atop k}\right\rbrace$ are the [Stirling numbers of the second kind](https://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind), which expand like this: \[ \frac 1 {6^n} \sum_{i=0}^6 \left(-1\right)^{6-i} i^n \binom 6 i \] (where $\binom n k$ are [binomial coefficients](https://en.wikipedia.org/wiki/Binomial_coefficient)) which simplifies to \[ \sum_{i=0}^6 \left(-1\right)^i \binom 6 i\left(\frac i 6\right)^n \] Note that the $i=0$ term is zero, but it is useful for me because it means the first term of the alternate sum has a positive coefficient. Code explanation: * `⍳7` To the list of numbers 0 through 6, apply the following function: * `!∘6` $\binom 6 x$ * `×` times * `6÷⍨⊢` $\frac x 6$ * `⍵*⍨` to the power of $n$ * `-/` and then take the alternate sum Kinda sad to see a bruteforce solution is smaller than the closed form, I'll try and find a language where this is even shorter :)