Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AoC-PS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ruben van Dijk
AoC-PS
Commits
a1c062f9
Commit
a1c062f9
authored
3 months ago
by
Ruben van Dijk
Browse files
Options
Downloads
Patches
Plain Diff
Day 18
parent
f95f17ce
Branches
master
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
days/18/1.ps1
+103
-0
103 additions, 0 deletions
days/18/1.ps1
days/18/2.ps1
+112
-0
112 additions, 0 deletions
days/18/2.ps1
days/18/input
+3450
-0
3450 additions, 0 deletions
days/18/input
with
3665 additions
and
0 deletions
days/18/1.ps1
0 → 100644
+
103
−
0
View file @
a1c062f9
Set-StrictMode
-Version
latest
$lines
=
Get-Content
-Path
$PSScriptRoot
\input
|
Select
-First
1024
$xSize
=
70
$ySize
=
70
$grid
=
@()
for
(
$y
=
0
;
$y
-le
$ySize
;
$y
++
)
{
$line
=
@()
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$line
+=
"."
}
$grid
+=
,
$line
}
function
drawGrid
{
$grid
|
ForEach-Object
{
$_
-join
' '
|
Write-Host
}
}
$lines
|
ForEach-Object
{
$parts
=
$_
-split
','
[
int
]
$x
=
$parts
[
0
]
[
int
]
$y
=
$parts
[
1
]
$grid
[
$y
][
$x
]
=
"#"
}
$grid
[
0
][
0
]
=
0
function
getValue
{
param
(
$x
,
$y
,
$xOffset
,
$yOffset
)
$x
+=
$xOffset
$y
+=
$yOffset
if
(
$y
-gt
$ySize
-or
$x
-gt
$xSize
)
{
return
100000
}
$value
=
$grid
[
$y
][
$x
]
if
(
$value
-eq
"#"
-or
$value
-eq
"."
)
{
$value
=
100000
}
return
$value
}
function
doCell
{
param
(
$x
,
$y
)
$current
=
$grid
[
$y
][
$x
]
if
(
$current
-eq
"#"
)
{
return
$false
}
if
(
$current
-eq
"."
)
{
$current
=
100000
}
$numbers
=
@(
$current
)
$numbers
+=
getValue
$x
$y
0
-1
$numbers
+=
getValue
$x
$y
0
1
$numbers
+=
getValue
$x
$y
-1
0
$numbers
+=
getValue
$x
$y
1
0
$measurement
=
$numbers
|
measure-object
-Minimum
$min
=
$measurement
.
Minimum
$min
+=
1
if
(
$current
-gt
$min
)
{
$grid
[
$y
][
$x
]
=
$min
$cellsChanged
+=
1
return
$true
}
else
{
return
$false
}
}
$changed
=
1
while
(
$changed
-ge
1
)
{
$changed
=
0
for
(
$y
=
0
;
$y
-le
$ySize
;
$y
++
)
{
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
for
(
$x
=
$xSize
;
$x
-ge
0
;
$x
--
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
}
for
(
$y
=
$ySize
;
$y
-ge
0
;
$y
--
)
{
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
for
(
$x
=
$xSize
;
$x
-ge
0
;
$x
--
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
}
Write-Host
"
$changed
cells changed"
}
$solution
=
$grid
[
$ySize
][
$xSize
]
Write-Host
"solution:
$solution
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
days/18/2.ps1
0 → 100644
+
112
−
0
View file @
a1c062f9
Set-StrictMode
-Version
latest
$xSize
=
70
$ySize
=
70
$lines
=
Get-Content
-Path
$PSScriptRoot
\input
function
getValue
{
param
(
$x
,
$y
,
$xOffset
,
$yOffset
)
$x
+=
$xOffset
$y
+=
$yOffset
if
(
$y
-gt
$ySize
-or
$x
-gt
$xSize
)
{
return
$false
}
return
$grid
[
$y
][
$x
]
-eq
"X"
}
function
doCell
{
param
(
$x
,
$y
)
$current
=
$grid
[
$y
][
$x
]
if
(
$current
-ne
"."
)
{
return
$false
}
$above
=
getValue
$x
$y
0
-1
$below
=
getValue
$x
$y
0
1
$left
=
getValue
$x
$y
-1
0
$right
=
getValue
$x
$y
1
0
if
(
$above
-or
$below
-or
$left
-or
$right
)
{
$grid
[
$y
][
$x
]
=
"X"
return
$true
}
else
{
return
$false
}
}
function
withAmount
{
param
(
$amount
)
$grid
=
@()
for
(
$y
=
0
;
$y
-le
$ySize
;
$y
++
)
{
$line
=
@()
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$line
+=
"."
}
$grid
+=
,
$line
}
$lines
|
Select
-First
$amount
|
ForEach-Object
{
$parts
=
$_
-split
','
[
int
]
$x
=
$parts
[
0
]
[
int
]
$y
=
$parts
[
1
]
$grid
[
$y
][
$x
]
=
"#"
}
$grid
[
0
][
0
]
=
"X"
$changed
=
1
while
(
$changed
-ge
1
)
{
$changed
=
0
for
(
$y
=
0
;
$y
-le
$ySize
;
$y
++
)
{
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
for
(
$x
=
$xSize
;
$x
-ge
0
;
$x
--
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
}
for
(
$y
=
$ySize
;
$y
-ge
0
;
$y
--
)
{
for
(
$x
=
0
;
$x
-le
$xSize
;
$x
++
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
for
(
$x
=
$xSize
;
$x
-ge
0
;
$x
--
)
{
$singleChanged
=
doCell
$x
$y
if
(
$singleChanged
)
{
$changed
+=
1
}
}
}
Write-Host
"
$changed
cells changed"
if
(
$grid
[
$ySize
][
$xSize
]
-eq
"X"
)
{
return
$true
}
}
return
$false
}
$min
=
0
$max
=
$lines
.
Length
while
(
$min
-ne
$max
)
{
Write-Host
"
$min
-
$max
"
$distance
=
$max
-
$min
[
int
]
$avg
=
$distance
/2
+
$min
Write-Host
"avg:
$avg
"
$finished
=
withAmount
$avg
Write-Host
"finished:
$finished
"
if
(
$distance
-eq
1
)
{
if
(
$finished
)
{
$min
=
$avg
$max
=
$avg
}
else
{
$min
=
$avg
-1
$max
=
$avg
-1
}
}
elseif
(
$finished
)
{
$min
=
$avg
}
else
{
$max
=
$avg
}
}
Write-Host
"solution:
$(
$lines
[
$min
]
)
"
This diff is collapsed.
Click to expand it.
days/18/input
0 → 100644
+
3450
−
0
View file @
a1c062f9
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment