diff --git a/ eds b/ eds deleted file mode 100644 index ce114e0..0000000 --- a/ eds +++ /dev/null @@ -1,25 +0,0 @@ -- [ ] V -- [ ] Swift -- [ ] Java -- [ ] C++ -- [ ] Elle -- [ ] Go -- [ ] Rust -- [ ] Dart -- [ ] SQL -- [ ] C -- [ ] C# -- [ ] Kotlin -- [ ] PHP -- [ ] JavaScript -- [ ] Crystal -- [ ] Bash -- [ ] Nim -- [ ] Perl -- [ ] Haskell -- [ ] Ruby -- [ ] pwsh -- [ ] F# -- [ ] Python -- [ ] Visual Basic -- [ ] Zig \ No newline at end of file diff --git a/.gitignore b/.gitignore index 14cb816..8a15a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ testing/ -input.txt \ No newline at end of file +input.txt +.idea/ \ No newline at end of file diff --git a/2024/README.md b/2024/README.md index 877f760..7910ee1 100644 --- a/2024/README.md +++ b/2024/README.md @@ -15,7 +15,7 @@ AOC but one programming language per day - [ ] SQL - [ ] C - [ ] C# -- [ ] Kotlin +- [x] 1: Kotlin (holy shit its actually a good lang) - [ ] PHP - [ ] JavaScript - [ ] Crystal diff --git a/2024/day1/example.txt b/2024/day1/example.txt new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/2024/day1/example.txt @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/2024/day1/solution.kts b/2024/day1/solution.kts new file mode 100755 index 0000000..dfc6eab --- /dev/null +++ b/2024/day1/solution.kts @@ -0,0 +1,92 @@ +#!/usr/bin/env kotlin + +import java.io.File +import java.util.Scanner +import kotlin.math.abs + +val expectedExampleAnswer = 11 +val secondExpectedExampleAnswer = 31 + +fun useProd(): Boolean { + print("Run on (p)roduction values or on (e)xample values w/ a known answer? >") + val scanner = Scanner(System.`in`) + val result = scanner.next().single() == 'p' + if(result) { + print("Running in production mode\n\n") + return true + } + print("\nRunning in example mode, expected values are $expectedExampleAnswer and $secondExpectedExampleAnswer\n") + return false +} + +fun getChallenge(): Char { + val scanner = Scanner(System.`in`) + print("Challenge (1) or (2)? >") + return scanner.next().single() +} + +fun challenge1(input: String): Int { + val lines = input.split("\n") + var invalidLines = 0 + val leftLocations: MutableList = mutableListOf() + val rightLocations: MutableList = mutableListOf() + var answer = 0 + + for(line in lines) { + val locations = line.split(" ") + try { + leftLocations += locations[0].toInt() + rightLocations += locations[1].toInt() + } + catch(e: Exception) { + invalidLines++ + continue + } + } + + for(i in 0.. = mutableListOf() + var rightLocations: MutableList = mutableListOf() + var answer = 0 + + for(line in lines) { + val locations = line.split(" ") + try { + leftLocations += locations[0].toInt() + rightLocations += locations[1].toInt() + } + catch(e: Exception) { + invalidLines++ + continue + } + } + + for(location in leftLocations) { + val amountOfTimes = rightLocations.count { it == location } + answer += location * amountOfTimes + } + + return answer +} + +val prodCheck = useProd() +val file = File(if(prodCheck) "input.txt" else "example.txt") +val content = file.readText() +val challengeNumber = getChallenge() + +val answer = if(challengeNumber == '1') challenge1(content) else if(challengeNumber == '2') challenge2(content) else 0 +println("The answer is $answer!") \ No newline at end of file