I'm trying to convert a Python script to PowerShell but I don't have any Python experience and it's getting long for a little piece of code.
def combinliste(seq, k):
p = []
i, imax = 0, 2**len(seq)-1
while i<=imax:
s = []
j, jmax = 0, len(seq)-1
while j<=jmax:
if (i>>j)&1==1:
s.append(seq[j])
j += 1
if len(s)==k:
p.append(s)
i += 1
return p
I have made something but I really don't know if it's correct.
What is += in PowerShell, is it same as Python?
function combinliste {
Param($seq, $k)
$p = @()
$i; $imax = 0, [Math]::Pow(2, $seq.Count) - 1
while ($i -le $jmax) {
$s = @()
$j, $jmax = 0, $seq.Count - 1
while ($j -le $jmax) {
if ($i -shr $j -band 1 -eq 1) {
$s + ($seq ???? #I don't know how to do it here
}
$j #humm.. 1
}
if ($s.Count -eq $k) {
$p + $s
}
$i #humm.. 1
return $p
}
}
I have tried few variations, but I'm lost.
get-help about_assignment_operators