Skip to content

Instantly share code, notes, and snippets.

Created January 2, 2014 08:26
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 anonymous/8216399 to your computer and use it in GitHub Desktop.
Save anonymous/8216399 to your computer and use it in GitHub Desktop.
function solve726_2 ([int]$n){
$a = 0..$n
$b = $a | % -begin{$acc=0} {$acc += $_; $acc}
$r0 = $n
for($l = 0; $l -lt $n; $l++){
for($r = $l+1; $r -le $n; $r++){
$x = $n - ($b[$r] - $b[$l])
if(0 -gt $x){ break }
if(0 -eq $x){ ,$a[($l+1)..$r]; break }
}
}
}
solve726_2 2014 | % {$_ -join ","}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment