How can I check if a 2 numbers have the same digits PowerShell?

Solution 1:

Here's one technique:

$null -eq (Compare-Object -ReferenceObject ([char[]][String]1260) -DifferenceObject ([char[]][String]2601))

Which returns true or false, depending on if the digits are the same or not.

Solution 2:

Here is another, a bit lengthier solution:

( $a.ToString().ToCharArray() | ForEach-Object { $c = $true } { if ( $b.ToString() -notmatch $_.ToString() ) { $c = $false } } { $c } ) -and ( $b.ToString().ToCharArray() | ForEach-Object { $c = $true } { if ( $a.ToString() -notmatch $_.ToString() ) { $c = $false } } { $c } )

This compares the int's as arrays and thus need to be run bothways.