Skip to content

Commit

Permalink
added scaffold for 2024 - updated dependencies and commented out som …
Browse files Browse the repository at this point in the history
…old code no longer working
  • Loading branch information
fmmr committed Nov 18, 2024
1 parent d89e3ef commit 3d2e5f3
Show file tree
Hide file tree
Showing 31 changed files with 251 additions and 136 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ fmmr solutions for Advent of code.

![stars](gifs/stars.png?raw=true "ascii art")

## 2023

[AOC](https://adventofcode.com/2024),
[Implementations](https://github.com/fmmr/advent/tree/master/src/main/kotlin/no/rodland/advent_2024),
[Tests](https://github.com/fmmr/advent/tree/master/src/test/kotlin/no/rodland/advent_2024)


## 2023

[AOC](https://adventofcode.com/2023),
Expand Down
22 changes: 11 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>

<kotlin.version>1.9.22</kotlin.version>
<kotlin.jvmTarget>21</kotlin.jvmTarget>
<kotlin.version>2.0.21</kotlin.version>
<kotlin.jvmTarget>22</kotlin.jvmTarget>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>

<assertj.version>3.24.2</assertj.version>
<guava.version>32.1.3-jre</guava.version>
<jacoco-maven-plugin.version>0.8.11</jacoco-maven-plugin.version>
<assertj.version>3.26.3</assertj.version>
<guava.version>33.3.1-jre</guava.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<jgrapht.version>1.5.2</jgrapht.version>
<junit.version>5.10.1</junit.version>
<junit.version>5.11.3</junit.version>
<klaxon.version>5.6</klaxon.version>
<kotlinx-coroutines.version>1.7.3</kotlinx-coroutines.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<surefire.version>3.2.2</surefire.version>
<kotlinx-coroutines.version>1.9.0</kotlinx-coroutines.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<surefire.version>3.5.2</surefire.version>
<version.json-simple>1.1.1</version.json-simple>
</properties>
<dependencyManagement>
Expand Down
133 changes: 66 additions & 67 deletions src/main/kotlin/no/rodland/advent_2019/Day07.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,78 @@ package no.rodland.advent_2019
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.toList
import kotlinx.coroutines.runBlocking

@DelicateCoroutinesApi
@ObsoleteCoroutinesApi
@ExperimentalCoroutinesApi
object Day07 {
fun partOne(program: List<String>): Long {
return permute(0..4).map { runBlocking { runAmplifiersPart1(program, it) } }.maxOrNull()!!
}

fun partTwo(program: List<String>): Long {
val map = permute(5..9).map { runBlocking { runAmplifiersPart2(program, it) } }
return map.maxOrNull()!!
}
// 20241118 commented out because BroadcastChannel is deprecated with ERROR. no simple replacement afaik.

@ExperimentalCoroutinesApi
@Suppress("DEPRECATION")
private suspend fun runAmplifiersPart2(program: List<String>, phases: List<Long>): Long {

val broadcast = BroadcastChannel<Long>(20)

val sniffer = broadcast.openSubscription()
val ea = broadcast.openSubscription()
val ab = Channel<Long>(20)
val bc = Channel<Long>(20)
val cd = Channel<Long>(20)
val de = Channel<Long>(20)

// set ut channels initially
broadcast.send(phases[0])
broadcast.send(0)

ab.send(phases[1])
bc.send(phases[2])
cd.send(phases[3])
de.send(phases[4])


// start each amplifier (justDoIt will do a launch)
val intCodeComputer4 = IntCodeComputer()
intCodeComputer4.launch(program, bc, cd)
val intCodeComputer3 = IntCodeComputer()
intCodeComputer3.launch(program, ea, ab)
val intCodeComputer2 = IntCodeComputer()
intCodeComputer2.launch(program, ab, bc)
val intCodeComputer1 = IntCodeComputer()
intCodeComputer1.launch(program, cd, de)
val intCodeComputer = IntCodeComputer()
intCodeComputer.launch(program, de, broadcast)

return sniffer.toList().last()
}

@ExperimentalCoroutinesApi
private suspend fun runAmplifiersPart1(program: List<String>, phases: List<Long>): Long {
var tmp = runAmp(program, phases[0], 0)
tmp = runAmp(program, phases[1], tmp)
tmp = runAmp(program, phases[2], tmp)
tmp = runAmp(program, phases[3], tmp)
return runAmp(program, phases[4], tmp)
}


suspend fun runAmp(program: List<String>, first: Long, second: Long): Long {
val inCh = Channel<Long>(20)
inCh.send(first)
inCh.send(second)
val list = mutableListOf<Long>()
IntCodeComputer().runSuspend(program, { inCh.receive() }, { list.add(it) })
return list.last()
}
// fun partOne(program: List<String>): Long {
// return permute(0..4).map { runBlocking { runAmplifiersPart1(program, it) } }.maxOrNull()!!
// }
//
// fun partTwo(program: List<String>): Long {
// val map = permute(5..9).map { runBlocking { runAmplifiersPart2(program, it) } }
// return map.maxOrNull()!!
// }
//
// @ExperimentalCoroutinesApi
// @Suppress("DEPRECATION")
// private suspend fun runAmplifiersPart2(program: List<String>, phases: List<Long>): Long {
//
// val broadcast = BroadcastChannel<Long>(20)
//
// val sniffer = broadcast.openSubscription()
// val ea = broadcast.openSubscription()
// val ab = Channel<Long>(20)
// val bc = Channel<Long>(20)
// val cd = Channel<Long>(20)
// val de = Channel<Long>(20)
//
// // set ut channels initially
// broadcast.send(phases[0])
// broadcast.send(0)
//
// ab.send(phases[1])
// bc.send(phases[2])
// cd.send(phases[3])
// de.send(phases[4])
//
//
// // start each amplifier (justDoIt will do a launch)
// val intCodeComputer4 = IntCodeComputer()
// intCodeComputer4.launch(program, bc, cd)
// val intCodeComputer3 = IntCodeComputer()
// intCodeComputer3.launch(program, ea, ab)
// val intCodeComputer2 = IntCodeComputer()
// intCodeComputer2.launch(program, ab, bc)
// val intCodeComputer1 = IntCodeComputer()
// intCodeComputer1.launch(program, cd, de)
// val intCodeComputer = IntCodeComputer()
// intCodeComputer.launch(program, de, broadcast)
//
// return sniffer.toList().last()
// }
//
// @ExperimentalCoroutinesApi
// private suspend fun runAmplifiersPart1(program: List<String>, phases: List<Long>): Long {
// var tmp = runAmp(program, phases[0], 0)
// tmp = runAmp(program, phases[1], tmp)
// tmp = runAmp(program, phases[2], tmp)
// tmp = runAmp(program, phases[3], tmp)
// return runAmp(program, phases[4], tmp)
// }
//
//
// suspend fun runAmp(program: List<String>, first: Long, second: Long): Long {
// val inCh = Channel<Long>(20)
// inCh.send(first)
// inCh.send(second)
// val list = mutableListOf<Long>()
// IntCodeComputer().runSuspend(program, { inCh.receive() }, { list.add(it) })
// return list.last()
// }
}

27 changes: 27 additions & 0 deletions src/main/kotlin/no/rodland/advent_2024/Day01.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package no.rodland.advent_2024

import no.rodland.advent.Day

// template generated: 18/11/2024
// Fredrik Rødland 2024

class Day01(val input: List<String>) : Day<Long, Long, List<String>> {

private val parsed = input.parse()

override fun partOne(): Long {
return 2
}

override fun partTwo(): Long {
return 2
}

override fun List<String>.parse(): List<String> {
return map { line ->
line
}
}

override val day = "01".toInt()
}
116 changes: 58 additions & 58 deletions src/test/kotlin/no/rodland/advent_2019/Day07Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,64 @@ import org.junit.jupiter.api.Test
internal class Day07Test {
val data07 = "2019/input_07.txt".readFirstLineStrings()

@Nested
inner class `Part 1` {
@Test
fun `07,1,test,1`() {
report {
Day07.partOne(listOf("3", "15", "3", "16", "1002", "16", "10", "16", "1", "16", "15", "15", "4", "15", "99", "0", "0")) to 43210L
}
}

@Test
fun `07,1,test,2`() {
report {
val program = listOf("3", "23", "3", "24", "1002", "24", "10", "24", "1002", "23", "-1", "23", "101", "5", "23", "23", "1", "24", "23", "23", "4", "23", "99", "0", "0")
Day07.partOne(program) to 54321L
}
}

@Test
fun `07,1,test,3`() {
report {
val program = listOf("3", "31", "3", "32", "1002", "32", "10", "32", "1001", "31", "-2", "31", "1007", "31", "0", "33", "1002", "33", "7", "33", "1", "33", "31", "31", "1", "32", "31", "31", "4", "31", "99", "0", "0", "0")
Day07.partOne(program) to 65210L
}
}

@Test
fun `07,1,live`() {
report {
Day07.partOne(data07) to 79723L
}
}
}

@Nested
inner class `Part 2` {
@Test
fun `07,2,test,1`() {
report {
val program = listOf("3", "26", "1001", "26", "-4", "26", "3", "27", "1002", "27", "2", "27", "1", "27", "26", "27", "4", "27", "1001", "28", "-1", "28", "1005", "28", "6", "99", "0", "0", "5")
Day07.partTwo(program) to 139629729L
}
}

@Test
fun `07,2,test,2`() {
report {
val program = listOf("3", "52", "1001", "52", "-5", "52", "3", "53", "1", "52", "56", "54", "1007", "54", "5", "55", "1005", "55", "26", "1001", "54", "-5", "54", "1105", "1", "12", "1", "53", "54", "53", "1008", "54", "0", "55", "1001", "55", "1", "55", "2", "53", "55", "53", "4", "53", "1001", "56", "-1", "56", "1005", "56", "6", "99", "0", "0", "0", "0", "10")
Day07.partTwo(program) to 18216L
}
}

@Test
fun `07,2,live`() {
report {
Day07.partTwo(data07) to 70602018L
}
}
}
// @Nested
// inner class `Part 1` {
// @Test
// fun `07,1,test,1`() {
// report {
// Day07.partOne(listOf("3", "15", "3", "16", "1002", "16", "10", "16", "1", "16", "15", "15", "4", "15", "99", "0", "0")) to 43210L
// }
// }
//
// @Test
// fun `07,1,test,2`() {
// report {
// val program = listOf("3", "23", "3", "24", "1002", "24", "10", "24", "1002", "23", "-1", "23", "101", "5", "23", "23", "1", "24", "23", "23", "4", "23", "99", "0", "0")
// Day07.partOne(program) to 54321L
// }
// }
//
// @Test
// fun `07,1,test,3`() {
// report {
// val program = listOf("3", "31", "3", "32", "1002", "32", "10", "32", "1001", "31", "-2", "31", "1007", "31", "0", "33", "1002", "33", "7", "33", "1", "33", "31", "31", "1", "32", "31", "31", "4", "31", "99", "0", "0", "0")
// Day07.partOne(program) to 65210L
// }
// }
//
// @Test
// fun `07,1,live`() {
// report {
// Day07.partOne(data07) to 79723L
// }
// }
// }
//
// @Nested
// inner class `Part 2` {
// @Test
// fun `07,2,test,1`() {
// report {
// val program = listOf("3", "26", "1001", "26", "-4", "26", "3", "27", "1002", "27", "2", "27", "1", "27", "26", "27", "4", "27", "1001", "28", "-1", "28", "1005", "28", "6", "99", "0", "0", "5")
// Day07.partTwo(program) to 139629729L
// }
// }
//
// @Test
// fun `07,2,test,2`() {
// report {
// val program = listOf("3", "52", "1001", "52", "-5", "52", "3", "53", "1", "52", "56", "54", "1007", "54", "5", "55", "1005", "55", "26", "1001", "54", "-5", "54", "1105", "1", "12", "1", "53", "54", "53", "1008", "54", "0", "55", "1001", "55", "1", "55", "2", "53", "55", "53", "4", "53", "1001", "56", "-1", "56", "1005", "56", "6", "99", "0", "0", "0", "0", "10")
// Day07.partTwo(program) to 18216L
// }
// }
//
// @Test
// fun `07,2,live`() {
// report {
// Day07.partTwo(data07) to 70602018L
// }
// }
// }
}


Loading

0 comments on commit 3d2e5f3

Please sign in to comment.