Nat Does Advent of Code 2025!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Day 9-2 and 10 Dev work

Nat M 1277b6b4 84837152

+251
+82
Day10/Day10-1.ps1
··· 1 + $inFile = $args[0] 2 + $inRaw = Get-Content $inFile 3 + 4 + class machine { 5 + [char[]] $lights 6 + [System.Collections.ArrayList] $buttons 7 + [int[]] $joltage 8 + 9 + [string] ToString() { 10 + $str = "" 11 + $btnNum = 0 12 + $str += "LIGHTS: $($this.lights)`n" 13 + $this.buttons | ForEach-Object { 14 + $str += "BUTTON $btnNum activates lights $($_.Lights)`n" 15 + } 16 + $str += "JOLTAGES: $($this.joltage)" 17 + return $str 18 + } 19 + 20 + [bool] TestButtons( [int[]] $PressedButtons ) { 21 + try { 22 + [char[]] $res = @() 23 + 0..($this.lights.Length - 1) | ForEach-Object { 24 + $res += '.' 25 + } 26 + $PressedButtons | forEach-Object { 27 + $foo = $_ 28 + $btn = $this.buttons[$foo] 29 + $btn.Lights | ForEach-Object { 30 + $bar = $_ 31 + switch ($res[$bar]) { 32 + '#' {$res[$bar] = '.'; break} 33 + '.' {$res[$bar] = '#'; break} 34 + } 35 + } 36 + 37 + Write-Host ("After button {0} is pressed, lights are {1}" -f $foo,[string]$res) 38 + } 39 + Write-Host ("RESULT: {0}`nLIGHTS: {1}" -f [string]$res,[string]$this.lights) 40 + return ([string]$res -eq [string]$this.lights) 41 + 42 + } 43 + catch { 44 + $foo = $Error[0].Exception.Message 45 + Write-Host "TestButtons failed due to error: $foo" 46 + return $false 47 + } 48 + } 49 + 50 + } 51 + 52 + class button { 53 + [int[]] $Lights 54 + } 55 + 56 + $machines = New-Object System.Collections.ArrayList 57 + 58 + $inRaw | ForEach-Object { 59 + $split = $_.split(" ") 60 + $tempMach = New-Object machine 61 + $tempMach.buttons = New-Object System.Collections.ArrayList 62 + $tempMach.lights = $split[0].Substring(1,($split[0].Length - 2)).ToCharArray() 63 + 1..($split.Length - 2) | ForEach-Object { 64 + $foo = New-Object button 65 + $split[$_].Substring(1, ($split[$_].Length - 2)).Split(",") | ForEach-Object {$foo.Lights += [int]$_} 66 + $tempMach.buttons.Add($foo) | Out-Null 67 + } 68 + $joltageStr = $split[-1].Substring(1,($split[-1].Length - 2)) 69 + $joltageStr.Split(",") | ForEach-Object { 70 + $tempMach.joltage += $_ 71 + } 72 + 73 + $machines.Add($tempMach) | Out-Null 74 + } 75 + 76 + $machines | ForEach-Object { 77 + Write-Host $_ 78 + } 79 + 80 + $testbuttons = @(0,1,2) 81 + $test1 = $machines[0].TestButtons($testbuttons) 82 + Write-Host "Results of $testbuttons on machine[0] is $test1."
Day10/input.txt

This is a binary file and will not be displayed.

+3
Day10/sample.txt
··· 1 + [.##.] (3) (1,3) (2) (2,3) (0,2) (0,1) {3,5,4,7} 2 + [...#.] (0,2,3,4) (2,3) (0,4) (0,1,2) (1,2,3,4) {7,5,12,7,2} 3 + [.###.#] (0,1,2,3,4) (0,3,4) (0,1,2,4,5) (1,2) {10,11,11,5,10,5}
+166
Day9/Day9-2.ps1
··· 1 + $inFile = $args[0] 2 + $inRaw = Get-Content $inFile 3 + 4 + $TileRows = @() 5 + $TileCols = @() 6 + 7 + $inRaw | ForEach-Object { 8 + $split = $_.Split(',') 9 + $tileRows += [int]$split[0] 10 + $tileCols += [int]$split[1] 11 + } 12 + 13 + function GetArea { 14 + param( [int]$ind1, [int]$ind2 ) 15 + $width = [Math]::Abs($tileRows[$ind1] - $tileRows[$ind2]) + 1 16 + $height = [Math]::Abs($tileCols[$ind1] - $tileCols[$ind2]) + 1 17 + 18 + return $height * $width 19 + } 20 + 21 + function CheckArea { 22 + param( [int]$ind1, [int]$ind2 ) 23 + $pass = $true 24 + 25 + if ($tileRows[$ind1] -gt $tileRows[$ind2]) { 26 + $Rowstart = $tileRows[$ind1] 27 + $Rowend = $tilerows[$ind2] 28 + } 29 + else { 30 + $Rowstart = $tileRows[$ind2] 31 + $Rowend = $tileRows[$ind1] 32 + } 33 + 34 + if ($tilecols[$ind1] -gt $tilecols[$ind2]) { 35 + $colstart = $tilecols[$ind1] 36 + $colend = $tilecols[$ind2] 37 + } 38 + else { 39 + $colstart = $tilecols[$ind2] 40 + $colend = $tilecols[$ind1] 41 + } 42 + 43 + $rowstart..$rowend | ForEach-Object { 44 + $foo = $_ 45 + $colstart..$colend | ForEach-Object { 46 + $bar = $_ 47 + 48 + if ($floor[$foo][$bar] -eq '.') { 49 + $pass = $false 50 + } 51 + } 52 + } 53 + 54 + return $pass 55 + } 56 + 57 + $maxArea = 0 58 + $MaxInd1 = 0 59 + $MaxInd2 = 0 60 + 61 + <# 62 + 0..$($TileRows.Count - 2) | ForEach-Object { 63 + $foo = $_ 64 + 1..$($TileRows.Count - 1) | ForEach-Object { 65 + $area = GetArea $foo $_ 66 + if ($area -gt $maxArea) { 67 + $maxArea = $area 68 + $MaxInd1 = $foo 69 + $MaxInd2 = $_ 70 + } 71 + } 72 + } 73 + 74 + Write-Host ("Max area is {0} with tiles at indices ({1}, {2}) and ({3},{4})." -f $maxArea,$tileRows[$MaxInd1],$TileCols[$MaxInd1],$TileRows[$MaxInd2],$TileCols[$MaxInd2]) 75 + #> 76 + 77 + # Get Min and Max of Arrays 78 + $rowMin = [int]::MaxValue 79 + $rowmax = 0 80 + $colmin = [int]::MaxValue 81 + $colmax = 0 82 + 83 + $tileRows | ForEach-Object { 84 + ($_ -lt $rowMin) ? $($rowMin = $_) : $null 85 + ($_ -gt $rowMax) ? $($rowMax = $_) : $null 86 + } 87 + 88 + $tileCols | ForEach-Object { 89 + ($_ -lt $colMin) ? $($colMin = $_) : $null 90 + ($_ -gt $colMax) ? $($colMax = $_) : $null 91 + } 92 + 93 + # Reduce values based on minimums 94 + 0..$($TileRows.Count -1 ) | ForEach-Object { 95 + $TileRows[$_] -= $rowMin 96 + $TileCols[$_] -= $colmin 97 + } 98 + $RowMax -= $rowMin 99 + $colmax -= $colmin 100 + $rowMin = 0 101 + $colmin = 0 102 + 103 + # Create Floor 104 + $floor = @($null) 105 + 0..$rowMax | ForEach-Object { 106 + $foo = $_ 107 + $floor += @($null) 108 + 0..$colMax | ForEach-Object { 109 + $floor[$foo] += ,'.' 110 + } 111 + } 112 + 113 + # Drop first tile 114 + $floor[$tileRows[0]][$TileCols[0]] = '#' 115 + #For every other tile, move from last tile to current tile and drop tiles along the way. 116 + 1..$($TileRows.Count - 1) | ForEach-Object { 117 + $rowcurrent = $tileRows[$_] 118 + $rowlast = $tilerows[$_ - 1] 119 + $colcurrent = $Tilecols[$_] 120 + $collast = $TileCols[$_ - 1] 121 + 122 + $rowlast..$rowcurrent | ForEach-Object { 123 + $foo = $_ 124 + $collast..$colcurrent | ForEach-Object { 125 + $bar = $_ 126 + $floor[$foo][$bar] = '#' 127 + } 128 + } 129 + } 130 + #Move from final tile to start 131 + $rowcurrent = $tileRows[0] 132 + $rowlast = $tilerows[$tilerows.Count - 1] 133 + $colcurrent = $Tilecols[0] 134 + $collast = $TileCols[$tilerows.Count - 1] 135 + 136 + $rowlast..$rowcurrent | ForEach-Object { 137 + $foo = $_ 138 + $collast..$colcurrent | ForEach-Object { 139 + $bar = $_ 140 + $floor[$foo][$bar] = '#' 141 + } 142 + } 143 + 144 + 145 + # Row by row, Fill in blank spaces 146 + 0..$($floor.Count - 2) | ForEach-Object { 147 + $inside = $false 148 + $foo = $_ 149 + Write-Host $floor[$foo] 150 + 0..$($floor[$foo].Count - 2) | ForEach-Object { 151 + $bar = $_ 152 + Write-Host $floor[$foo][$bar] 153 + switch ($floor[$foo][$bar]) { 154 + '.' {$inside ? $($floor[$foo][$bar] = '#') : $null} 155 + '#' {$inside ? $($inside = $false) : $(if ($floor[$foo][$bar + 1] -eq '.') {$inside = $true})} 156 + } 157 + } 158 + } 159 + 160 + 161 + $floor | ForEach-Object { 162 + $_ | ForEach-Object { 163 + Write-Host $_ -NoNewline 164 + } 165 + Write-Host "" 166 + }