1
$\begingroup$

if I say to input 3, how do I get MMA to make me a table with all the cases on the left, in the center their frequency and on the right a histogram,bar chart, or some other way to represent the above. Thanks in advance

t = Input["Give Sum"];
Select[Tuples[Range[6], 3], Total[#] >= t &]

Edited something like this I need or similar

output

$\endgroup$
3
  • $\begingroup$ All the outcomes given by your second line has the same probability. Do you want to ignore the order of throws? sorted = Sort /@ list; outcomes = Sort@(StringJoin[ToString /@ #] & /@ sorted) $\endgroup$
    – Domen
    Commented Aug 22, 2021 at 0:18
  • $\begingroup$ @Domen.thanks for the answer, if I want them to be only combinations, it doesn't matter the order. could you put the complete code , when I implement it I get this error "Sort::normal: Nonatomic expression expected at position 1 in Sort[list]. $\endgroup$
    – BeTDa
    Commented Aug 22, 2021 at 0:43
  • $\begingroup$ GroupBy[Tuples[Range[6], 3], Total] may get you started. $\endgroup$
    – Roman
    Commented Aug 22, 2021 at 5:23

1 Answer 1

1
$\begingroup$
data = KeySort@GroupBy[Tuples[Range[6], 3], Total]
(*    <|3 -> {{1, 1, 1}},
        4 -> {{1, 1, 2}, {1, 2, 1}, {2, 1, 1}},
        ...
        17 -> {{5, 6, 6}, {6, 5, 6}, {6, 6, 5}},
        18 -> {{6, 6, 6}}|>                         *)

MatrixForm[Prepend[
  KeyValueMap[{#2, #1, Length[#2]} &, data],
  {"cases", "sum", "frequency"}]]

(*    cases                               sum   frequency
      {{1, 1, 1}}                           3           1
      {{1, 1, 2}, {1, 2, 1}, {2, 1, 1}}     4           3
      ...
      {{5, 6, 6}, {6, 5, 6}, {6, 6, 5}}    17           3
      {{6, 6, 6}}                          18           1    *)

ListPlot[KeyValueMap[{#1, Length[#2]} &, data], Filling -> Axis]

enter image description here

$\endgroup$
1
  • $\begingroup$ thank you very much, just what I needed $\endgroup$
    – BeTDa
    Commented Aug 22, 2021 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.