## Combination without repitition

## Combination without repitition

(OP)

Hi guys

I am hoping someone can help me with this PowerShell script.

The script lists the unique combination of 26 letter alphabet ($List) based on 3 letter ($k)

If I keep the $List shorter like A to K for instance, it works. But with 26 letter it doesn't work

Thank you

############

$List = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"

$k = 3

Add-Type @"

public class Shift {

public static int Right(int x, int count) { return x >> count; }

public static uint Right(uint x, int count) { return x >> count; }

public static long Right(long x, int count) { return x >> count; }

public static ulong Right(ulong x, int count) { return x >> count; }

public static int Left(int x, int count) { return x << count; }

public static uint Left(uint x, int count) { return x << count; }

public static long Left(long x, int count) { return x << count; }

public static ulong Left(ulong x, int count) { return x << count; }

}

"@

function CombinationWithoutRepetition ([int]$k, $List)

{

Function IsNBits ([long]$value, $k, $length)

{

$count = 0

for ($i = 0 ; $i -le $length ; $i++)

{

if ($value -band 1)

{

$count++

}

$value = [shift]::Right($value,1)

}

if ($count -eq $k)

{

return $true

}

else

{

return $false

}

}

Function BitsToArray ([long]$value, $List)

{

$res = @()

for ($i = 0 ; $i -le $List.length ; $i++)

{

if ($value -band 1)

{

$res += $List[$i]

}

$value = [shift]::Right($value,1)

}

return ,$res

}

[long]$i = [Math]::Pow(2, $List.Length)

$res = @()

for ([long]$value=0 ; $value -le $i ; $value++)

{

if ((IsNBits $value $k $List.Length) -eq $true)

{

#write-host $value

$res += ,(BitsToArray $value $List)

}

}

return ,$res

}

Clear-Host

$res = CombinationWithoutRepetition $k $List

$res.count

$res | Sort-Object | % { $_ -join ','}

I am hoping someone can help me with this PowerShell script.

The script lists the unique combination of 26 letter alphabet ($List) based on 3 letter ($k)

If I keep the $List shorter like A to K for instance, it works. But with 26 letter it doesn't work

Thank you

############

$List = "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"

$k = 3

Add-Type @"

public class Shift {

public static int Right(int x, int count) { return x >> count; }

public static uint Right(uint x, int count) { return x >> count; }

public static long Right(long x, int count) { return x >> count; }

public static ulong Right(ulong x, int count) { return x >> count; }

public static int Left(int x, int count) { return x << count; }

public static uint Left(uint x, int count) { return x << count; }

public static long Left(long x, int count) { return x << count; }

public static ulong Left(ulong x, int count) { return x << count; }

}

"@

function CombinationWithoutRepetition ([int]$k, $List)

{

Function IsNBits ([long]$value, $k, $length)

{

$count = 0

for ($i = 0 ; $i -le $length ; $i++)

{

if ($value -band 1)

{

$count++

}

$value = [shift]::Right($value,1)

}

if ($count -eq $k)

{

return $true

}

else

{

return $false

}

}

Function BitsToArray ([long]$value, $List)

{

$res = @()

for ($i = 0 ; $i -le $List.length ; $i++)

{

if ($value -band 1)

{

$res += $List[$i]

}

$value = [shift]::Right($value,1)

}

return ,$res

}

[long]$i = [Math]::Pow(2, $List.Length)

$res = @()

for ([long]$value=0 ; $value -le $i ; $value++)

{

if ((IsNBits $value $k $List.Length) -eq $true)

{

#write-host $value

$res += ,(BitsToArray $value $List)

}

}

return ,$res

}

Clear-Host

$res = CombinationWithoutRepetition $k $List

$res.count

$res | Sort-Object | % { $_ -join ','}

## RE: Combination without repitition

## CODE -->

Light travels faster than sound. That's why some people appear bright until you hear them speak.

## RE: Combination without repitition

I am looking for unique list like ABC, ABD etc. Also position of letters doesn't matter. i.e ABC = BCA, so BCA shouldn't be listed

## RE: Combination without repitition

## RE: Combination without repitition

I don't think that would work, because you'd never get AA*. The first TLA would be ABC.

Blue,

It isn't very elegant, but try this:

## CODE -->

Light travels faster than sound. That's why some people appear bright until you hear them speak.