Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Part 1
- # In how many assignment pairs does one range fully contain the other?
- [string[]]$assignments = $puzzleInput -split '\n' | Select -SkipLast 1
- $fullyContain = 0
- $answers = foreach ($pair in $assignments) {
- [int]$p1l, [int]$p1h, [int]$p2l, [int]$p2h = $pair -split '-|,'
- if (($p1l -le $p2l -and $p1h -ge $p2h) -or ($p2l -le $p1l -and $p2h -ge $p1h)) {
- $fullyContain++
- }
- }
- $fullyContain
- # Part 2
- # In how many assignment pairs do the ranges overlap?
- $overlap = 0
- $answers = foreach ($pair in $assignments) {
- [int]$p1l, [int]$p1h, [int]$p2l, [int]$p2h = $pair -split '-|,'
- $elf1 = $p1l..$p1h
- $elf2 = $p2l..$p2h
- if (Compare $elf1 $elf2 -ExcludeDifferent -IncludeEqual) {
- $overlap++
- }
- }
- $overlap
Advertisement
Add Comment
Please, Sign In to add comment