-
Notifications
You must be signed in to change notification settings - Fork 0
/
day11.ps1
70 lines (43 loc) · 1.19 KB
/
day11.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# AOC Day 11
# https://adventofcode.com/2024/day/11
#$data = "125 17"
$data = "92 0 286041 8034 34394 795 8 2051489"
$temp = $data -split " "
# Part 1
$buffer = new-object System.Collections.ArrayList
$myqueue = new-object System.Collections.queue
for ($x = 0; $x -lt $temp.count; $x++) {
[void]$buffer.Add([int64]::Parse($temp[$x]))
}
$blinks = 1
$blinkcount =75
while ($blinks -le $blinkcount) {
for ($i=0; $i -lt $buffer.count; $i++) {
$number = $buffer[$i].ToString()
$length = $number.length
$num = [convert]::ToInt64($number)
if ($num -eq 0) {$myqueue.Enqueue(1) }
elseif ($Length % 2 -eq 0 ) {
$midpoint = $length / 2
$left = $number.Substring(0,($midpoint))
$right =$number.Substring($midpoint)
#write-host $buffer
$lval = [convert]::ToInt64($left)
$rval = [convert]::toint64($right)
$myqueue.Enqueue($lval)
$myqueue.Enqueue($rval)
} else {
$num2 = $num * 2024
$myqueue.Enqueue($num2)
}
}
#$new = $myqueue.ToArray()
#[array]::Reverse($new)
#$new -join ","
$total = $myqueue.count
$buffer.Clear()
while ($myqueue.count -gt 0) { [void]$buffer.Add($myqueue.Dequeue()) }
$blinks +=1
write-host $blinks
}
write-host $total