Skip to content

Instantly share code, notes, and snippets.

@tech-zombie
Last active Dec 6, 2020
Embed
What would you like to do?
AdventOfCodeDay5
#####puzzle can be found here: https://adventofcode.com/2020/day/5
$list = gc .\day5Input.txt
$highest =0
foreach ($ticket in $list)
{
$rowCode = $ticket.Substring(0,7).ToCharArray()
$columnCode = $ticket.Substring(7,3).ToCharArray()
$rowLowerbound = 0
$rowUpperbound = 127
foreach ($letter in $rowcode)
{
if ($letter -eq "F") { $rowUpperbound = (($rowLowerbound+$rowUpperbound- 1 )/2 ) }
if ($letter -eq "B") { $rowLowerbound = (($rowUpperbound - $rowLowerbound + 1)/2) + $rowLowerbound }
}
$columnLowerbound = 0
$columnUpperbound = 7
foreach ($letter in $columnCode)
{
if ($letter -eq "L") {$columnUpperbound = (($columnLowerbound+$columnUpperbound- 1 )/2 ) }
if ($letter -eq "R") {$columnLowerbound = (($columnUpperbound - $columnLowerbound + 1)/2) + $columnLowerbound }
}
$seatID = $rowLowerbound * 8 + $columnLowerBound
if ($seatID -gt $highest)
{$highest = $seatID}
}
$highest
$list = gc .\day5Input.txt
$highest =0
$seatingPlan = @()
foreach ($ticket in $list)
{
$rowCode = $ticket.Substring(0,7).ToCharArray()
$columnCode = $ticket.Substring(7,3).ToCharArray()
$rowLowerbound = 0
$rowUpperbound = 127
foreach ($letter in $rowcode)
{
if ($letter -eq "F") { $rowUpperbound = (($rowLowerbound+$rowUpperbound- 1 )/2 ) }
if ($letter -eq "B") { $rowLowerbound = (($rowUpperbound - $rowLowerbound + 1)/2) + $rowLowerbound }
}
$columnLowerbound = 0
$columnUpperbound = 7
foreach ($letter in $columnCode)
{
if ($letter -eq "L") {$columnUpperbound = (($columnLowerbound+$columnUpperbound- 1 )/2 ) }
if ($letter -eq "R") {$columnLowerbound = (($columnUpperbound - $columnLowerbound + 1)/2) + $columnLowerbound }
}
$seatID = $rowLowerbound * 8 + $columnLowerBound
#"$ticket - Row: $rowLowerBound - Column: $columnLowerBound - SeatID: $seatID"
if ($seatID -gt $highest)
{$highest = $seatID}
$seatingPlan = $seatingplan + $seatID
}
$highest
$seatingplan = $seatingPlan | sort
$lastSeat = 0
foreach ($seat in $seatingplan)
{
if ($seat-$lastSeat -eq 2)
{ $seat - 1 }
$lastSeat = $seat
}
$ticket = "FBFBBFFRLL"
$rowCode = $ticket.Substring(0,7)
$rowcode = ($rowcode -replace "F","0")-replace "B","1"
[convert]::ToInt32($rowcode,2)
BFBFFBBRLR
FBFBFFBRLL
BFBFBFFRLR
BFFBFBFRLL
FFBFFFBRLL
BFBFFFFLRR
BFBFBFBRRL
BFBFFFBLRL
BFFBBBBRLR
BFFBFFFLRL
BFBFBFBLRR
FBFFBFBRLL
BFFFFBBLRL
FBFBFBBLLL
FFFBFBBLRR
FBFFFBFRLL
FFFBBFBLLL
BFFBBFFRRR
BFFBBFBLRL
BFFFBBBRLR
BFFBFFBLRR
FFBBFFFLRL
BFBBBBBRLR
BFBFBBBRRR
FBFFBFBLRR
FBBFBBBRLR
FBFFFBBLLR
BFFBBBBRRR
BFBFBFFRLL
FFFBFBFLLL
BBFFFBBRLR
BFBFFFFRLR
BFBBBFBLRL
FBBBBFFRLR
FFBBBBFRRR
FBFBFFFLRR
FFFBFFBLRL
BFFFFBBLRR
FFBFFFBLLR
FBFFFFFRLL
BFFFFBFLRR
BBFFFFFLLL
FBFFBBBRLL
FBFFFFBLLR
BFFFFFBRRR
BFBFFFFRRL
FBBBBFBRRR
FBFBFFFLLL
FBFFFFBRRL
FFBBFFBRRR
FBFFBBFLLL
FFBFBBBRLL
BFBFFFFLRL
FFBFFFFLRL
BFBFFFBRLR
FFFBFBFRRR
BFBFBBFRLL
FFBFFBBLRR
FBBFBBBRRL
FFBBFFBRLL
FBFBBBBRRR
BFBBFFBLLL
BFBFBBBRLR
FFBBFBBLLL
BBFFBBBLRL
FBFBBBBLRL
FBFFFBFLLR
FFFBFBBLRL
FBBBFFBLLL
FFBFBBFLLR
FBFFFFBLRR
FFBBFBBRLR
BBFFFBBRRR
BF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