This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.pow | |
const val boardSize = 10 | |
fun cost(solution: Array<Int>): Int { | |
var cost = 0 | |
for (i in 0 until boardSize) { | |
for (j in (i + 1) until boardSize) { | |
if (solution[i] == solution[j]) cost++ | |
if (solution[i] == solution[j] + (j - i)) cost++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.pow | |
import kotlin.random.Random | |
const val boardSize = 40 | |
const val tries = 100 | |
val random = Random(System.currentTimeMillis()) | |
fun cost(solution: Array<Int>): Int { | |
var cost = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val startPoint = "A" | |
private const val finalPoint = "G" | |
data class Vertex(val id: String, val length: Int) | |
// adjacency list graph | |
val graph = | |
mapOf( | |
"A" to listOf(Vertex("B", 3), Vertex("C", 5)), | |
"B" to listOf(Vertex("A", 3), Vertex("D", 4), Vertex("E", 2)), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xyz.kandrac.u | |
import androidx.compose.foundation.layout.Box | |
import androidx.compose.foundation.layout.BoxWithConstraints | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.offset | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.material3.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.runtime.mutableStateOf |
OlderNewer