LabtechConsulting
12/3/2016 - 11:26 PM

Advent of Code Day3 http://adventofcode.com/2016/day/3

$List = (Invoke-WebRequest 'https://gist.githubusercontent.com/LabtechConsulting/15114472e85f3b8a666dc0a404916772/raw/1458df8ca91f4db6518ec95c3bec91e922ebac09/new_gist_file_0').Content

function Sort-List {
    param(
        $List
    )
    begin{
        $Temp1 = @()
        $Temp2 = @()
        $Temp3 = @()
        $Temp4 = @()
        $TempVar = @()
        $NewList = @()
        $NewArray2 = @()
        $List = $List -split '[\r\n]'
    }
    process{
        foreach($item in $List){
            $NewList += $item -split ' ' | where {$_}
        }
        $NewList | foreach {$i=1} {if ($i++ %3){$Temp1 += $_}else{$Temp2 += $_}}
        $Temp1 | foreach {$i=1} {if ($i++ %2){$Temp3 += $_}else{$Temp4 += $_}}


        $NewArray = $Temp3 + $Temp4 + $Temp2
        
        $Count = 0
        foreach($item in $NewArray){
            $count ++
            $TempVar = "$TempVar $item"
            if($Count -eq 3){
                $NewArray2 += $TempVar
                $TempVar = @()
                $Count = 0
            }
        }
    }
end{$NewArray2}
}

function Count-Triangles {
    Param(
        $List
    )
    $Triangle = 0
    foreach($Item in $List){
        $Sides = ($item -split ' ' | where {$_}).trim()
        [int]$Hypotenuse = ($Sides | measure -Maximum).maximum
        if((($Sides | measure -Sum).sum - $Hypotenuse) -gt $Hypotenuse){$Triangle ++}
    }
    Write-Output $Triangle
}

Count-Triangles $($List -split '[\r\n]' | where{$_})

$List = Sort-List $List

Count-Triangles $List