From 46e919eb23f1c88423d8bb88dd5f457119e50bd3 Mon Sep 17 00:00:00 2001 From: shoofle Date: Mon, 11 Dec 2023 20:11:22 -0500 Subject: [PATCH] days 1-3 --- .gitignore | 1 + day01/.gitignore | 29 ++++++++++++++ day01/.idea/.gitignore | 8 ++++ day01/.idea/codeStyles/Project.xml | 10 +++++ day01/.idea/codeStyles/codeStyleConfig.xml | 5 +++ .../inspectionProfiles/Project_Default.xml | 6 +++ day01/.idea/kotlinc.xml | 10 +++++ day01/.idea/libraries/KotlinJavaRuntime.xml | 26 +++++++++++++ day01/.idea/misc.xml | 6 +++ day01/.idea/modules.xml | 8 ++++ day01/.idea/vcs.xml | 6 +++ day01/day01.iml | 15 +++++++ day01/src/Main.kt | 26 +++++++++++++ day02/.gitignore | 29 ++++++++++++++ day02/.idea/.gitignore | 8 ++++ .../inspectionProfiles/Project_Default.xml | 6 +++ day02/.idea/kotlinc.xml | 10 +++++ day02/.idea/libraries/KotlinJavaRuntime.xml | 26 +++++++++++++ day02/.idea/misc.xml | 6 +++ day02/.idea/modules.xml | 8 ++++ day02/.idea/vcs.xml | 6 +++ day02/day02.iml | 15 +++++++ day02/src/Main.kt | 39 +++++++++++++++++++ day03/.gitignore | 29 ++++++++++++++ day03/.idea/.gitignore | 8 ++++ .../inspectionProfiles/Project_Default.xml | 6 +++ day03/.idea/kotlinc.xml | 10 +++++ day03/.idea/libraries/KotlinJavaRuntime.xml | 26 +++++++++++++ day03/.idea/misc.xml | 6 +++ day03/.idea/modules.xml | 8 ++++ day03/.idea/vcs.xml | 6 +++ day03/day03.iml | 15 +++++++ day03/src/Main.kt | 22 +++++++++++ 33 files changed, 445 insertions(+) create mode 100644 .gitignore create mode 100644 day01/.gitignore create mode 100644 day01/.idea/.gitignore create mode 100644 day01/.idea/codeStyles/Project.xml create mode 100644 day01/.idea/codeStyles/codeStyleConfig.xml create mode 100644 day01/.idea/inspectionProfiles/Project_Default.xml create mode 100644 day01/.idea/kotlinc.xml create mode 100644 day01/.idea/libraries/KotlinJavaRuntime.xml create mode 100644 day01/.idea/misc.xml create mode 100644 day01/.idea/modules.xml create mode 100644 day01/.idea/vcs.xml create mode 100644 day01/day01.iml create mode 100644 day01/src/Main.kt create mode 100644 day02/.gitignore create mode 100644 day02/.idea/.gitignore create mode 100644 day02/.idea/inspectionProfiles/Project_Default.xml create mode 100644 day02/.idea/kotlinc.xml create mode 100644 day02/.idea/libraries/KotlinJavaRuntime.xml create mode 100644 day02/.idea/misc.xml create mode 100644 day02/.idea/modules.xml create mode 100644 day02/.idea/vcs.xml create mode 100644 day02/day02.iml create mode 100644 day02/src/Main.kt create mode 100644 day03/.gitignore create mode 100644 day03/.idea/.gitignore create mode 100644 day03/.idea/inspectionProfiles/Project_Default.xml create mode 100644 day03/.idea/kotlinc.xml create mode 100644 day03/.idea/libraries/KotlinJavaRuntime.xml create mode 100644 day03/.idea/misc.xml create mode 100644 day03/.idea/modules.xml create mode 100644 day03/.idea/vcs.xml create mode 100644 day03/day03.iml create mode 100644 day03/src/Main.kt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..162238c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/*.input diff --git a/day01/.gitignore b/day01/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/day01/.gitignore @@ -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 \ No newline at end of file diff --git a/day01/.idea/.gitignore b/day01/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/day01/.idea/.gitignore @@ -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 diff --git a/day01/.idea/codeStyles/Project.xml b/day01/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/day01/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/day01/.idea/codeStyles/codeStyleConfig.xml b/day01/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/day01/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/day01/.idea/inspectionProfiles/Project_Default.xml b/day01/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/day01/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/day01/.idea/kotlinc.xml b/day01/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/day01/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/day01/.idea/libraries/KotlinJavaRuntime.xml b/day01/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..30d5a17 --- /dev/null +++ b/day01/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day01/.idea/misc.xml b/day01/.idea/misc.xml new file mode 100644 index 0000000..69ace3f --- /dev/null +++ b/day01/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day01/.idea/modules.xml b/day01/.idea/modules.xml new file mode 100644 index 0000000..a3d1aa1 --- /dev/null +++ b/day01/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/day01/.idea/vcs.xml b/day01/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/day01/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day01/day01.iml b/day01/day01.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/day01/day01.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day01/src/Main.kt b/day01/src/Main.kt new file mode 100644 index 0000000..6ac8e16 --- /dev/null +++ b/day01/src/Main.kt @@ -0,0 +1,26 @@ +import java.io.File +import kotlin.math.max + +//TIP Press twice to open the Search Everywhere dialog and type show whitespaces, +// then press . You can now see whitespace characters in your code. +fun main() { + val elves = mutableListOf(); + var elf = 0; + + for (line in File("b.input").readLines()) { + if (line.isEmpty()) { + elves.add(elf); + elf = 0; + } else { + elf += line.toInt(); + } + } + if (elf != 0) elves.add(elf); + + val heaviest = elves.sortedDescending().first(); + println("heaviest elf load is $heaviest") + + val heaviestThree = elves.sortedDescending().take(3).reduce { a,b -> a+b }; + println("heaviest three are $heaviestThree"); + +} \ No newline at end of file diff --git a/day02/.gitignore b/day02/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/day02/.gitignore @@ -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 \ No newline at end of file diff --git a/day02/.idea/.gitignore b/day02/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/day02/.idea/.gitignore @@ -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 diff --git a/day02/.idea/inspectionProfiles/Project_Default.xml b/day02/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/day02/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/day02/.idea/kotlinc.xml b/day02/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/day02/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/day02/.idea/libraries/KotlinJavaRuntime.xml b/day02/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..30d5a17 --- /dev/null +++ b/day02/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day02/.idea/misc.xml b/day02/.idea/misc.xml new file mode 100644 index 0000000..69ace3f --- /dev/null +++ b/day02/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day02/.idea/modules.xml b/day02/.idea/modules.xml new file mode 100644 index 0000000..ccba9a1 --- /dev/null +++ b/day02/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/day02/.idea/vcs.xml b/day02/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/day02/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day02/day02.iml b/day02/day02.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/day02/day02.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day02/src/Main.kt b/day02/src/Main.kt new file mode 100644 index 0000000..cfa0bee --- /dev/null +++ b/day02/src/Main.kt @@ -0,0 +1,39 @@ +import java.io.File + +//TIP Press twice to open the Search Everywhere dialog and type show whitespaces, +// then press . You can now see whitespace characters in your code. +fun main() { + val answer = File("b.input").readLines(); + println("answer is ${answer.map { match(it) }.sum()}"); + println("b answer is ${answer.map { match_b(it) }.sum()}"); +} + +fun match(m: String): Int { + return when (m) { + "A X" -> 4 + "A Y" -> 8 + "A Z" -> 3 + "B X" -> 1 + "B Y" -> 5 + "B Z" -> 9 + "C X" -> 7 + "C Y" -> 2 + "C Z" -> 6 + else -> 0 + } +} + +fun match_b(m: String): Int { + return when (m) { + "A X" -> (3+0) //they chose rock, we lose, so we chose scissors (3) + "A Y" -> (1+3) // they chose rock, we draw, so we chose rock (1) + "A Z" -> (2+6) //they chose rock, we win, so we chose paper (2) + "B X" -> (1+0) // they chose paper, we lose, so we chose rock (1) + "B Y" -> (2+3) // they chose paper, we draw, so we chose paper (2) + "B Z" -> (3+6) + "C X" -> (2+0) // they chose scissors, we lose, so we chose paper (2) + "C Y" -> (3+3) + "C Z" -> (1+6) + else -> 0 + } +} \ No newline at end of file diff --git a/day03/.gitignore b/day03/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/day03/.gitignore @@ -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 \ No newline at end of file diff --git a/day03/.idea/.gitignore b/day03/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/day03/.idea/.gitignore @@ -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 diff --git a/day03/.idea/inspectionProfiles/Project_Default.xml b/day03/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..df543e3 --- /dev/null +++ b/day03/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/day03/.idea/kotlinc.xml b/day03/.idea/kotlinc.xml new file mode 100644 index 0000000..5cba058 --- /dev/null +++ b/day03/.idea/kotlinc.xml @@ -0,0 +1,10 @@ + + + + + + + \ No newline at end of file diff --git a/day03/.idea/libraries/KotlinJavaRuntime.xml b/day03/.idea/libraries/KotlinJavaRuntime.xml new file mode 100644 index 0000000..30d5a17 --- /dev/null +++ b/day03/.idea/libraries/KotlinJavaRuntime.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day03/.idea/misc.xml b/day03/.idea/misc.xml new file mode 100644 index 0000000..69ace3f --- /dev/null +++ b/day03/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day03/.idea/modules.xml b/day03/.idea/modules.xml new file mode 100644 index 0000000..6c80244 --- /dev/null +++ b/day03/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/day03/.idea/vcs.xml b/day03/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/day03/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/day03/day03.iml b/day03/day03.iml new file mode 100644 index 0000000..43dd653 --- /dev/null +++ b/day03/day03.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/day03/src/Main.kt b/day03/src/Main.kt new file mode 100644 index 0000000..16a9dca --- /dev/null +++ b/day03/src/Main.kt @@ -0,0 +1,22 @@ +import java.io.File + +//TIP Press twice to open the Search Everywhere dialog and type show whitespaces, +// then press . You can now see whitespace characters in your code. +fun main() { + val file = File("a.input").readLines(); + val sum = file.map { findOverlap(it) } .map { priority(it) }.sum(); + println("the sum of item priorities is $sum"); + + val badges = file.chunked(3).map {findShared(it.toSet())} .map {priority(it)}.sum(); + println("the sum of badge priorities is $badges"); +} + +fun findShared(bags: Set): Char { + return bags.map { it.toSet() }.reduce {a,b -> a intersect b} .first(); +} +fun findOverlap(input: String): Char { + return findShared(input.chunked(input.length / 2).toSet()); +} +fun priority(c: Char): Int { + return "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(c) + 1; +} \ No newline at end of file