Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I modified the source beforehand to replace all spaces with commas
- $lines = [IO.File]::ReadAllText("D:\scripts\Day3\Sequences.txt") -split "[\r\n]" | where {$_}
- # My modification left a comma at the beginning of every line
- # Remove preceding commas
- for($i=0;$i -lt $lines.length; $i++){
- $lines[$i] = $lines[$i].substring(1)
- }
- # Set my counters
- $possible = 0
- $impossible = 0
- # Check each line
- foreach($line in $lines){
- $triangle = $line -split ','
- $a = [int]$triangle[0]
- $b = [int]$triangle[1]
- $c = [int]$triangle[2]
- if(($a + $b -gt $c) -and ($a + $c -gt $b) -and ($b + $c -gt $a)){
- $possible++
- }
- else{
- $impossible++
- }
- }
- write-host "Number of possible triangles" = $possible
- write-host "Number of impossible triangles" = $impossible
Advertisement
Add Comment
Please, Sign In to add comment