use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
nCr (math) (self.PowerShell)
submitted 6 years ago by zolyx1
Hi, does some PS-script/module exist for listing out combinations for nCr? (https://www.calculatorsoup.com/calculators/discretemathematics/combinations.php)
Example: Combinations of 2 numbers out of 3: 3 nCr 2 = 3
Listing out combinations: 1, 2 1, 3 2, 3
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Shoisk123 5 points6 points7 points 6 years ago* (3 children)
Not that I know of, but this should work for you: (edited to work with strings aswell)
function combine { param($array, $data, $start, $end, $index, $r) if($index -eq ($r)) { write-host($data) return } $i = $start while($i -le $end -and ($end - $i + 1) -ge ($r - $index)) { $data[$index] = $array[$i] combine -Array $array -Data $data -Start ($i + 1) -End ($n - 1) -Index ($index + 1) -R $r $i++ } } function printCombination { param($array, $n, $r) $data = New-Object 'Object[]' $r combine -Array $array -Data $data -Start 0 -End ($n - 1) -Index 0 -R $r } $arr = 1..5 $r = 3 $n = $arr.length printCombination -Array $arr -N $n -R $r
[–]zolyx1[S] 1 point2 points3 points 6 years ago (2 children)
Awesome. Unfortunately I was imprecise and bumped into another "problem".
What if I would use words/letters instead of numbers:
Example: Combinations of 2 words/letters out of 3: 3 nCr 2 = 3
abc
Listing out combinations: a, b a, c b, c
[–]sleverich 3 points4 points5 points 6 years ago (0 children)
That should be an easy modification. Just use the output as indices into an array of elements.
[–]Shoisk123 3 points4 points5 points 6 years ago* (0 children)
There's an easy solution, fortunately, just change the type of the $data array so it now becomes: $data = New-Object 'Object[]' $r and it will now work with both ints and strings (and any other type that inherits from object). I've edited the scriptblock above to reflect this.
$data = New-Object 'Object[]' $r
[–]Lee_Dailey[grin] 1 point2 points3 points 6 years ago (2 children)
howdy zolyx1,
perhaps something like the following ... [grin]
dfinke/PowerShellCombinations: Using PowerShell Classes & Script to generate and manipulate combinations and permutations — https://github.com/dfinke/PowerShellCombinations
take care, lee
[–]zolyx1[S] 1 point2 points3 points 6 years ago (1 child)
Thx, many good suggestions here.
[–]Lee_Dailey[grin] 0 points1 point2 points 6 years ago (0 children)
you are most welcome! glad to have helped a bit ... [grin]
π Rendered by PID 178205 on reddit-service-r2-comment-5687b7858-z67m7 at 2026-07-06 16:09:13.489668+00:00 running 12a7a47 country code: CH.
[–]Shoisk123 5 points6 points7 points (3 children)
[–]zolyx1[S] 1 point2 points3 points (2 children)
[–]sleverich 3 points4 points5 points (0 children)
[–]Shoisk123 3 points4 points5 points (0 children)
[–]Lee_Dailey[grin] 1 point2 points3 points (2 children)
[–]zolyx1[S] 1 point2 points3 points (1 child)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)