Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Equilibrium-index/PowerShell/equilibrium-index-1.psh
Normal file
22
Task/Equilibrium-index/PowerShell/equilibrium-index-1.psh
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
function Get-EquilibriumIndex ( $Sequence )
|
||||
{
|
||||
$Indexes = 0..($Sequence.Count - 1)
|
||||
$EqulibriumIndex = @()
|
||||
|
||||
ForEach ( $TestIndex in $Indexes )
|
||||
{
|
||||
$Left = 0
|
||||
$Right = 0
|
||||
ForEach ( $Index in $Indexes )
|
||||
{
|
||||
If ( $Index -lt $TestIndex ) { $Left += $Sequence[$Index] }
|
||||
ElseIf ( $Index -gt $TestIndex ) { $Right += $Sequence[$Index] }
|
||||
}
|
||||
|
||||
If ( $Left -eq $Right )
|
||||
{
|
||||
$EqulibriumIndex += $TestIndex
|
||||
}
|
||||
}
|
||||
return $EqulibriumIndex
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Get-EquilibriumIndex -7, 1, 5, 2, -4, 3, 0
|
||||
Loading…
Add table
Add a link
Reference in a new issue