Timeline for Generating ordered n-tuples with k distinct elements
Current License: CC BY-SA 4.0
10 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 12 at 9:45 | comment | added | Vosoni | Patterns[11, 10] returns 55 results, as it should. Thanks a lot for help. | |
Oct 12 at 9:43 | comment | added | Vosoni |
This is the version of the code in the form of a function: Patterns[len_, k_] := ( Clear[dfs]; ResultingPatterns = {}; dfs[number_List] := If[Length[number] == len, If[Length[Union[If[# < 10, #, 0] & /@ number]] == k, AppendTo[ResultingPatterns, If[# < 10, #, 0] & /@ number]], Do[If[i <= 10, dfs[Append[number, i]]], {i, Range[1, Last[Union[number]] + 1]}] ]; dfs[{1}]; FromDigits /@ ResultingPatterns ); Patterns[11, 10]
|
|
Oct 12 at 9:42 | comment | added | Vosoni |
Or, rather, {i, Range[1, Last[Union[number]] + 1]}
|
|
Oct 12 at 9:37 | comment | added | Vosoni |
It should be {i, Range[1, Last[number] + 1]} because zero comes at the end, then it works.
|
|
Oct 12 at 9:32 | comment | added | AsukaMinato |
@Vosoni change to {i, Range[0, Last[number] + 1]} in Do , but it will print one more dup result.
|
|
Oct 12 at 9:25 | comment | added | Vosoni | I just realized that I made a mistake in my problem statement, therefore I edited it. Every next digit should be at most by 1 larger than the maximum of the preceding digits, sorry for this mistake. My old description did not match the code. | |
Oct 12 at 9:10 | vote | accept | Vosoni | ||
Oct 12 at 9:10 | vote | accept | Vosoni | ||
Oct 12 at 9:10 | |||||
Oct 12 at 9:10 | comment | added | Vosoni | Thank you! This is indeed much faster, though I don't quite understand how it works. ;-) | |
Oct 12 at 9:00 | history | answered | AsukaMinato | CC BY-SA 4.0 |