Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
Last active August 5, 2020 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbvf50mobile/2d08e6e6d42cd2bfb46cb192655de77b to your computer and use it in GitHub Desktop.
Save lbvf50mobile/2d08e6e6d42cd2bfb46cb192655de77b to your computer and use it in GitHub Desktop.
Just PHP FUN 068.
<?php
function find_even_index($arr){
$s = []; $prv = 0;
foreach($arr as $v){ array_push($s, $prv + $v); $prv += $v;}
for($prv = 0, $i = 0, $total = $s[count($s)-1]; $i < count($s); $i+=1){
if($prv === $total - $prv - $arr[$i]) return $i;
$prv = $s[$i];
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment