crlogic

Day6

Dec 6th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. [char[]]$stream ??= $puzzleInput -split '\n' | Select -SkipLast 1
  2.  
  3. Function Get-Header {
  4. Param($stream,$uniqueCount)
  5. Process {
  6. $queue = [System.Collections.Queue]::new()
  7. for ($i = 0; $i -lt $stream.count; $i++) {
  8. [void]$queue.Enqueue($stream[$i])
  9. if (($queue | group).Name.count -eq $uniqueCount) {break}
  10. if (($queue.count % $uniqueCount) -eq 0) {$queue.Dequeue()}
  11. }
  12. $i+1
  13. }
  14. }
  15.  
  16. Get-Header $stream 4
  17. # Part 2
  18. Get-Header $stream 14
Advertisement
Add Comment
Please, Sign In to add comment