From f2497d4e3a3e706cdc9fb483ce7ead57b0cbda71 Mon Sep 17 00:00:00 2001 From: Tyler Beckman Date: Fri, 6 Dec 2024 18:42:19 -0700 Subject: [PATCH] Day 6 optimized --- day6/part2-optimized.kts | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 day6/part2-optimized.kts diff --git a/day6/part2-optimized.kts b/day6/part2-optimized.kts new file mode 100644 index 0000000..3c30c9d --- /dev/null +++ b/day6/part2-optimized.kts @@ -0,0 +1,60 @@ +#!/usr/bin/env kotlin + +import java.io.File + +fun MutableList>.clone(): MutableList> { + val grid = mutableListOf>() + var i = 0; + this.forEach { + grid.add(MutableList(it.size) { j -> + this[i][j] + }) + i++ + } + + return grid +} + +enum class Direction { + UP, + DOWN, + RIGHT, + LEFT; + + fun rotate90(): Direction { + return when (this) { + UP -> RIGHT + DOWN -> LEFT + RIGHT -> DOWN + LEFT -> UP + } + } +} + +var originalGrid = mutableListOf>() + +var originalGuy = Pair(0, 0); +var originalDirection = Direction.UP + +var i = 0 +File("./input.txt").forEachLine { + val iter = it.chars().iterator() + var j = 0 + originalGrid.add(MutableList(it.length) { + var next = iter.next().toChar() + + if (next == '^') { + originalGuy = Pair(i, j) + next = '.' + } + + j++ + next + }) + + i++ +} + + + +println("\n" + sum) \ No newline at end of file