2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 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
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
function equil($arr){
|
||||
$res=@()
|
||||
for($i=0;$i -lt $arr.length;$i++){
|
||||
$left=0;$right=0
|
||||
|
||||
for($j=0;$j -lt $arr.length;$j++){
|
||||
if ($j -lt $i){$left+=$arr[$j]}
|
||||
if ($j -gt $i){$right+=$arr[$j]}
|
||||
}
|
||||
if($left -eq $right){$res+=$i}
|
||||
}
|
||||
[String]$res
|
||||
}
|
||||
|
||||
equil -7,1,5,2,-4,3,0
|
||||
Loading…
Add table
Add a link
Reference in a new issue