第三题

This commit is contained in:
SOR
2026-09-21 18:29:12 +08:00
parent 1e681dc684
commit 9e00d89e03
4 changed files with 57 additions and 17 deletions
+1 -1
View File
@@ -41,5 +41,5 @@
![start.png](assets/start.png)
测试通过会会给出接下来的迷题位置,也可以在 [目录测试类](src/test/kotlin/io/github/sor2171/puzzles/Catalog.kt) 中查看所有迷题。
测试通过会给出接下来的迷题位置,也可以在 [目录测试类](src/test/kotlin/io/github/sor2171/puzzles/Catalog.kt) 中查看所有迷题。
@@ -7,17 +7,27 @@ class PuzzleNote(
vararg notes: PuzzleNote? = arrayOf(null)
) {
val className = CompileDetector.getColoredName(className)
val notes = notes.filterNotNull()
val notes = notes
override fun toString(): String {
val validNotes = notes
if (validNotes.isEmpty()) return className
val sb = StringBuilder()
val builder = StringBuilder(className)
builder.append("\n │")
for (note in validNotes) {
builder.append("\n ├ ").append(note)
sb.append(className)
if (notes.size > 1) {
for (i in 1 until notes.size) {
sb.append("\n │")
notes[i]?.let { note ->
sb.append("\n ├── ").append(note.className)
}
}
}
return builder.toString()
val nextNote = notes.firstOrNull()
if (nextNote != null) {
sb.append("\n │\n").append(nextNote.toString())
}
return sb.toString()
}
}
@@ -26,18 +26,22 @@ object CatalogStructure {
val firstPuzzleNote: PuzzleNote
get() {
var lastNote: PuzzleNote? = null
var nextMainNote: PuzzleNote? = null
for (i in puzzlesArray.indices.reversed()) {
val array = puzzlesArray[i]
val noteArray = Array(array.size - 1) { i ->
PuzzleNote(array[i + 1])
val children = Array(array.size) { index ->
if (index == 0) {
nextMainNote
} else {
PuzzleNote(array[index])
}
}
lastNote = PuzzleNote(
array[0],
*noteArray
)
nextMainNote = PuzzleNote(array[0], *children)
}
return lastNote!!
return nextMainNote!!
}
fun printAllMessage() = println(firstPuzzleNote)
@@ -0,0 +1,26 @@
@file:SkipCompile(skip = true)
@file:Suppress("ClassName")
package io.github.sor2171.puzzles.alphabet
import io.github.sor2171.puzzles.annotation.SkipCompile
import org.junit.jupiter.api.Test
/**
* 你需要写一个函数,目标是把一个 [Pair] 的两个值相交换
*/
class `You need a function, not a mathematical one` {
// write start 1
fun
// write end 1
@Test
fun puzzle() {
val pair = "abc" to 123
val new = exchange(pair)
println(pair)
println(new)
assert(new.first == pair.second && new.second == pair.first)
}
}