Skip to main content
added 3 characters in body
Source Link
kirma
  • 19.1k
  • 1
  • 55
  • 95

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Edit: Obviously my answer has also components from David Carraher. Or rather, I figured out an identical construct without reading that answer first...

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Edit: Obviously my answer has also components from David Carraher. Or rather, I figured out identical construct without reading that answer first...

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Edit: Obviously my answer has also components from David Carraher. Or rather, I figured out an identical construct without reading that answer first...

added 152 characters in body
Source Link
kirma
  • 19.1k
  • 1
  • 55
  • 95

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Edit: Obviously my answer has also components from David Carraher. Or rather, I figured out identical construct without reading that answer first...

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.

Edit: Obviously my answer has also components from David Carraher. Or rather, I figured out identical construct without reading that answer first...

Source Link
kirma
  • 19.1k
  • 1
  • 55
  • 95

Variation on Lou's answer:

Total[Length[Permutations[#]] & /@
  (Reduce[a + b + c + d + e + f == 18 && 
    0 <= a <= b <= c <= d <= e <= f <= 9,
    {a, b, c, d, e, f}, Integers] /.
  {Or | And -> List, _ == v_Integer :> v})] // AbsoluteTiming

{0.022396, 25927}

It is not that pretty, but avoids explicitly finding all permutations on a result list of Reduce. Instead, amount of permutations every ordered value could produce is counted and summed afterwards. This is relatively faster with six variables, and increasingly so with higher amount of variables.