659
edits
Carandraug (talk | contribs) (new section for combinatorics with problem permutations with repetition) |
Carandraug (talk | contribs) (→Combinatorics: Combinations with string characters) |
||
Line 143: | Line 143: | ||
== Combinatorics == | == Combinatorics == | ||
=== Combinations with string characters === | |||
==== Problem ==== | |||
You want to get all combinations of different letters but {{codeline|nchoosek}} only accepts numeric input. | |||
==== Solution ==== | |||
Convert your string to numbers and then back to characters. | |||
{{Code||<syntaxhighlight lang="octave"> | |||
char (nchoosek (uint8 (string), n) | |||
</syntaxhighlight>}} | |||
==== Discussion ==== | |||
A string in Octave is just a character matrix and can easily be converted to numeric form back and forth. Each character has an associated number (the {{codeline|asci}} function of the {{forge|miscellaneous}} package displays a nicely formatted conversion table). | |||
=== Permutations with repetition === | === Permutations with repetition === | ||
==== Problem ==== | ==== Problem ==== | ||
Line 162: | Line 175: | ||
combs = cell2mat (cellfun (@(c) c(:), cart, "UniformOutput", false)); | combs = cell2mat (cellfun (@(c) c(:), cart, "UniformOutput", false)); | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
== Mathematics == | == Mathematics == |