added 2024 part 1
This commit is contained in:
29
2024/06/Kotlin/.gitignore
vendored
Normal file
29
2024/06/Kotlin/.gitignore
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
8
2024/06/Kotlin/.idea/.gitignore
generated
vendored
Normal file
8
2024/06/Kotlin/.idea/.gitignore
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
6
2024/06/Kotlin/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
6
2024/06/Kotlin/.idea/inspectionProfiles/Project_Default.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||
</profile>
|
||||
</component>
|
||||
10
2024/06/Kotlin/.idea/kotlinc.xml
generated
Normal file
10
2024/06/Kotlin/.idea/kotlinc.xml
generated
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Kotlin2JvmCompilerArguments">
|
||||
<option name="jvmTarget" value="1.8" />
|
||||
</component>
|
||||
<component name="KotlinCommonCompilerArguments">
|
||||
<option name="apiVersion" value="2.0" />
|
||||
<option name="languageVersion" value="2.0" />
|
||||
</component>
|
||||
</project>
|
||||
17
2024/06/Kotlin/.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
17
2024/06/Kotlin/.idea/libraries/KotlinJavaRuntime.xml
generated
Normal file
@@ -0,0 +1,17 @@
|
||||
<component name="libraryTable">
|
||||
<library name="KotlinJavaRuntime" type="repository">
|
||||
<properties maven-id="org.jetbrains.kotlin:kotlin-stdlib:2.0.0" />
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-javadoc.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/2.0.0/kotlin-stdlib-2.0.0-sources.jar!/" />
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
||||
6
2024/06/Kotlin/.idea/misc.xml
generated
Normal file
6
2024/06/Kotlin/.idea/misc.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_22" default="true" project-jdk-name="22" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
8
2024/06/Kotlin/.idea/modules.xml
generated
Normal file
8
2024/06/Kotlin/.idea/modules.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Kotlin.iml" filepath="$PROJECT_DIR$/Kotlin.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
15
2024/06/Kotlin/Kotlin.iml
Normal file
15
2024/06/Kotlin/Kotlin.iml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
99
2024/06/Kotlin/src/Main.kt
Normal file
99
2024/06/Kotlin/src/Main.kt
Normal file
@@ -0,0 +1,99 @@
|
||||
import java.io.File
|
||||
|
||||
fun main() {
|
||||
val filenames = listOf("example.txt", "input.txt")
|
||||
filenames.forEach { filename ->
|
||||
val input = readInput(filename)
|
||||
val (map, guard) = generateMap(input)
|
||||
println("${filename.dropLast(4)} Guard Step Count: ${getWalkCount(map, guard)}")
|
||||
//println("${filename.dropLast(4)} Incorrect Middle Sum: $incorrect")
|
||||
}
|
||||
}
|
||||
fun readInput(filename: String) = File("src/$filename").readText()
|
||||
fun generateMap(input: String): Pair<List<List<Pair<String, Boolean>>>, Pair<Int, Int>> {
|
||||
var guardCord = Pair(0, 0)
|
||||
val map = input.lines().mapIndexed { x, line ->
|
||||
line.trim().split("").mapIndexed { y, tile ->
|
||||
when (tile) {
|
||||
"^" -> {
|
||||
guardCord = Pair(x, y)
|
||||
Pair(tile, false)
|
||||
}
|
||||
else -> Pair(tile, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
return Pair(map, guardCord)
|
||||
}
|
||||
fun getWalkCount(map: List<List<Pair<String, Boolean>>>, guardCord: Pair<Int, Int>): Int {
|
||||
val mutableMap = map.map { it.toMutableList() }.toMutableList()
|
||||
var count = 1
|
||||
var direction = Direction.UP
|
||||
var currentLocation = guardCord
|
||||
var outOfBounds = false
|
||||
while (!outOfBounds){
|
||||
try {
|
||||
when (direction){
|
||||
Direction.UP -> {
|
||||
val front = mutableMap[currentLocation.first - 1][currentLocation.second]
|
||||
if (front.first == "#") {
|
||||
direction = Direction.RIGHT
|
||||
} else {
|
||||
if (!mutableMap[currentLocation.first][currentLocation.second].second){
|
||||
count = count.inc()
|
||||
mutableMap[currentLocation.first][currentLocation.second] = mutableMap[currentLocation.first][currentLocation.second].copy(second = true, first = "@")
|
||||
}
|
||||
currentLocation = Pair(currentLocation.first - 1, currentLocation.second)
|
||||
}
|
||||
}
|
||||
Direction.DOWN -> {
|
||||
val front = mutableMap[currentLocation.first + 1][currentLocation.second]
|
||||
if (front.first == "#") {
|
||||
direction = Direction.LEFT
|
||||
} else {
|
||||
if (!mutableMap[currentLocation.first][currentLocation.second].second){
|
||||
count = count.inc()
|
||||
mutableMap[currentLocation.first][currentLocation.second] = mutableMap[currentLocation.first][currentLocation.second].copy(second = true, first = "@")
|
||||
}
|
||||
currentLocation = Pair(currentLocation.first + 1, currentLocation.second)
|
||||
}
|
||||
}
|
||||
Direction.RIGHT -> {
|
||||
val front = mutableMap[currentLocation.first][currentLocation.second + 1]
|
||||
if (front.first == "#") {
|
||||
direction = Direction.DOWN
|
||||
} else {
|
||||
if (!mutableMap[currentLocation.first][currentLocation.second].second){
|
||||
count = count.inc()
|
||||
mutableMap[currentLocation.first][currentLocation.second] = mutableMap[currentLocation.first][currentLocation.second].copy(second = true, first = "@")
|
||||
}
|
||||
currentLocation = Pair(currentLocation.first, currentLocation.second + 1)
|
||||
}
|
||||
}
|
||||
Direction.LEFT -> {
|
||||
val front = mutableMap[currentLocation.first][currentLocation.second - 1]
|
||||
if (front.first == "#") {
|
||||
direction = Direction.UP
|
||||
} else {
|
||||
if (!mutableMap[currentLocation.first][currentLocation.second].second){
|
||||
count = count.inc()
|
||||
mutableMap[currentLocation.first][currentLocation.second] = mutableMap[currentLocation.first][currentLocation.second].copy(second = true, first = "@")
|
||||
}
|
||||
currentLocation = Pair(currentLocation.first, currentLocation.second - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
//println(mutableMap.map { it.map { it.first }.joinToString("") }.joinToString("\n"))
|
||||
} catch (e: IndexOutOfBoundsException) {
|
||||
outOfBounds = true
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
enum class Direction(){
|
||||
UP,
|
||||
DOWN,
|
||||
RIGHT,
|
||||
LEFT
|
||||
}
|
||||
10
2024/06/Kotlin/src/example.txt
Normal file
10
2024/06/Kotlin/src/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
....#.....
|
||||
.........#
|
||||
..........
|
||||
..#.......
|
||||
.......#..
|
||||
..........
|
||||
.#..^.....
|
||||
........#.
|
||||
#.........
|
||||
......#...
|
||||
130
2024/06/Kotlin/src/input.txt
Normal file
130
2024/06/Kotlin/src/input.txt
Normal file
@@ -0,0 +1,130 @@
|
||||
..................#................................................................#........#.....................................
|
||||
...#...........#...................................................#........................................#.................#...
|
||||
...................................#................#.#...............#.................................................#.........
|
||||
.....#......#................#.....................................................................#..........#........#......#...
|
||||
............................................................................................#.....................#...............
|
||||
.....................#..##...#........................#.................#.......................#..#.........#.......#...#......#.
|
||||
............##....................................##..................#...............................#....#......................
|
||||
.............#............#.#..#.......#...........#..............#...............#.....#.........................................
|
||||
....................#..........##.........#.........#................#............................................................
|
||||
....#.......#................................................................#...#.#..........................................#.#.
|
||||
..#..............#.....................................#..........#.#....#..............#..................#.#............#.......
|
||||
.#.......#.........................#........................#..#.....#............................................................
|
||||
........#...#......................#...........#......................................#....................#......................
|
||||
.............................#..............#........##....#....................#......#....................#............#......#.
|
||||
..............#..............#............#.......................##....#..........................................#.........#....
|
||||
.............#............#..........#..........#...#.....................................................#.......................
|
||||
..#........#.....#..........................................#................................................#...#.#...#..........
|
||||
........#.....................#...#..#......#.........................................................#.....##.........#..........
|
||||
..............................................................................................#...#...............................
|
||||
..#.......................#..........................#......#...................................................................#.
|
||||
.......#.........................#..............#.........#.............#.......................................#...#.............
|
||||
..................#.................#.......................#....................#....................................#...........
|
||||
...#...#.......#......##.#...............#....#..............#..........................................#....#..#.................
|
||||
#................................#.......#.....#.......#.............#..................#........#................................
|
||||
...........#..................................#.......................................................................#.#..#......
|
||||
.......#........#.........................................#..........................#...........................#.....#..........
|
||||
................#..#.....................#..#...........................#...........................................#.............
|
||||
#...#.......................#................................................#................#................................#..
|
||||
..........#...........................#.......#............................................................................#.....#
|
||||
..................................#............................................................#..................................
|
||||
......................#........#.............#....#.....#.......#..........................#..........................#...........
|
||||
...........................##.................#.............#........................#...#..................#.....................
|
||||
.............................................................................................................#....#..........#....
|
||||
................#...................................#...........#..........#....................#............................#....
|
||||
........#....#................................................#................##..#..................................#...........
|
||||
...........#....................................................#...#.#......#....................................................
|
||||
.......................#.........................................................^....................................#...........
|
||||
..........................#.............##..#........#.#....#.......#....................#...........#.........#.....#............
|
||||
........#...........................#..#..........................................................#...............................
|
||||
....#....................................#....#.........................................#.........#...............................
|
||||
...............#...................................#.....#.................................#....................................#.
|
||||
......#...............................................................#.............................#........................#....
|
||||
.........................#.....#.........................#.#...............#.........#.....#..................#..#.........#......
|
||||
.........................................................#......#........##.......................#...#......#................#...
|
||||
.......................................#.....#.................................#..................................................
|
||||
..................#..................................#..........................................................................#.
|
||||
...................#....#.........#.......#................#....................#.........................#......#.....#..#.......
|
||||
................................#..............................................................................#....#.............
|
||||
.....................#.#.............#.................#..........#.......#.........................................#.............
|
||||
......#....................#....................................................................#...#.............................
|
||||
........#........#...........#.##.............#........................#............#..............#.........#....#........#......
|
||||
........................#.................................................................#.......................................
|
||||
............................................................#.....#....................#............#.....#....#............#.....
|
||||
...........#............#....#........................................................##............#..............#..............
|
||||
...........#...........#.....#..............#..............##....#........#......#................................................
|
||||
..#................................................................................#......................#......#................
|
||||
....................#.........#......................#.............................#.......#.......................#.............#
|
||||
..#...#....#......................................................................................................#...............
|
||||
...........#................................................................................#...............................#.....
|
||||
....................................#............#..........#.........................#..................................#.......#
|
||||
...................#......#...................#............#......#........#................#.............#...........#.........#.
|
||||
........................#..................................#........#..................#..........................................
|
||||
............#..#...........#..................##....................#...........................................#.................
|
||||
.......................................................................................#.....#............#.......................
|
||||
...............................................#....#................................#..#..........................#..#...........
|
||||
..............#..#.....#.........#....................#.......#..#..............#...............................#.....#...........
|
||||
..........#............................#..........................................................................................
|
||||
........................................#........#........................................................#.#.....................
|
||||
#................#......................#..................................................................................#......
|
||||
...............................................................................#................................#.................
|
||||
...................................................................................................................#.#........#...
|
||||
#........................................................................#......................................#.#...............
|
||||
...#......#............#...................#.............#........#..........................................#......#.............
|
||||
..............##....#...................................................#......................#..................................
|
||||
...............#........................................................................#...........#...#.#.......................
|
||||
..........#.#.....#................................#...........#........#.......#.................................................
|
||||
#....................#......................................................................................#.....................
|
||||
..............#...##...........................................#.............#.......#..................#..............#..........
|
||||
.#.............................................#..............................................................................#...
|
||||
...#................................#............................................#............................#...................
|
||||
..............................#......................................................#..........................................#.
|
||||
...................#.....................................#..................................#......#..............................
|
||||
....#.#..........##.............#.......#........................##..........#.................#..................................
|
||||
#..#................#........##....................................................................................#..............
|
||||
........#...#.........................................................................#...........................................
|
||||
......................................................#....#...................#..#.................................#.............
|
||||
........#...............#........#..............................................#............................#....................
|
||||
...#..............................#.........................................##.......................................#....#.......
|
||||
...#................#..............#.......#......................................................................................
|
||||
........#..................#.............................................................#...........................#....#.......
|
||||
......................#.#..........#.......#..................................#..#...#............#...............#...............
|
||||
.....#..................#....#..#......#.......................#.....................................................#............
|
||||
.....#................................#.........................#..................#.#..........#...#............#.....#..........
|
||||
....#...................#....#.#.........#........#..................................................................#....#..#....
|
||||
........#...............#......................................#........#..............................#..........................
|
||||
....#...#.#.....#..............#..................#..........#...#..#......................#...#..........#......................#
|
||||
...........#...................................................................................................#................#.
|
||||
.................................##..............#.............................#...............................#..................
|
||||
...........#.................#.............##...................................#.......................#.................##......
|
||||
.....#..................#......#........#.................................................#..#........................#..#........
|
||||
......#.......#......................................................................#.#.........#....#...........................
|
||||
..................#.#........................#......#................................................................#......#.....
|
||||
.....................#............#...................#.....#....................................#.......#..........#.......#.....
|
||||
#.............................#...............................#...#...............................................................
|
||||
..##.........#........#......................................#.....................#...#.............#............#..#............
|
||||
..........#.....................#..#....................#...#....................#....................#.....................#.....
|
||||
...........#..........#...............#..#..........#..............................................#.#............................
|
||||
............#...#...#.............#.........#.............................#...............#.......................................
|
||||
.........#...........#...............................................................#............................................
|
||||
.#..#.................................................................#............#.#.......................##...................
|
||||
........##............#...................#................................#......................................................
|
||||
............................................#..........................#..........................................................
|
||||
#...................#...........#..............#...#............#.#........#.................#......#.............................
|
||||
........#....................................#....................................................................................
|
||||
...........#.........#..#...............#...........#.....##.#......#....##............#....#....#.#.........##.........#.........
|
||||
..#......................#..........#.................#.................#......#.............................#........#...........
|
||||
....................#.................#....#..............................#....#.............#....#....#.....................#....
|
||||
............#.................#.................................#...............................#..#...........................#..
|
||||
...................................................#.....#..............#.......#....................#.#..........................
|
||||
..#.........##..#........#...................................................................................#............#.......
|
||||
.....#..............................#......................................................................#........#.............
|
||||
................................#........##.......#...............#..............#.......#...#.#........#.........................
|
||||
..............................#.....................#.........................................#..................................#
|
||||
...........#...................##.................#.................................#...............................#........#....
|
||||
..............................#...##......#..................#...#................................#......#.......#...............#
|
||||
.....................##......#......#.#.......#..............#......#.................#.........#...................#.............
|
||||
..........................#................................#...........#..........................................................
|
||||
...#.....#....................#.....................#...#.....#.............................#.#....#.....#.#.................#....
|
||||
............................#...#........#......................................................................#.....#...........
|
||||
............#..........##..................#.............................................................#.....#..#...............
|
||||
Reference in New Issue
Block a user