File tree Expand file tree Collapse file tree 1 file changed +6
-30
lines changed
Expand file tree Collapse file tree 1 file changed +6
-30
lines changed Original file line number Diff line number Diff line change 1- import de.ronny_h.extensions.isSymmetrical
2-
31fun main () {
42 val day = " Day14"
53
@@ -103,50 +101,28 @@ fun main() {
103101
104102 println (" $day part 2" )
105103
106- fun List<Robot>.isNotSymmetrical (width : Int , height : Int ): Boolean {
104+ fun List<Robot>.isNotUnique (width : Int , height : Int ): Boolean {
107105 val grid = toGrid(width, height)
108- val symmetrical = grid.all { row ->
109- row.isSymmetrical()
106+ val allUnique = grid.all { row ->
107+ row.all { it <= 1 }
110108 }
111- if (symmetrical ) {
109+ if (allUnique ) {
112110 grid.print ()
113111 }
114- return ! symmetrical
112+ return ! allUnique
115113 }
116114
117115 fun iterateUntilSymmetrical (robots : List <Robot >, width : Int , height : Int ): Long {
118116 var seconds = 0L
119117 do {
120118 seconds++
121- if (seconds % 10000 == 0L ) print (' .' )
122- if (seconds % 1000000 == 0L ) println ()
123119 val result = robots.move(width, height, seconds)
124- } while (result.isNotSymmetrical (width, height))
120+ } while (result.isNotUnique (width, height))
125121 return seconds
126122 }
127123
128- fun part2Small (input : List <String >) = iterateUntilSymmetrical(input.parseRobots(), 11 , 7 )
129-
130124 fun part2 (input : List <String >) = iterateUntilSymmetrical(input.parseRobots(), 101 , 103 )
131125
132- printAndCheck(
133- """
134- p=0,4 v=3,-3
135- p=6,3 v=-1,-3
136- p=10,3 v=-1,2
137- p=2,0 v=2,-1
138- p=0,0 v=1,3
139- p=3,0 v=-2,-2
140- p=7,6 v=-1,-3
141- p=3,0 v=-1,-2
142- p=9,3 v=2,3
143- p=7,3 v=-1,2
144- p=2,4 v=2,-3
145- p=9,5 v=-3,-3
146- """ .trimIndent().lines(),
147- ::part2Small, 2
148- )
149-
150126 printAndCheck(input, ::part2, 91649162 )
151127}
152128
You can’t perform that action at this time.
0 commit comments