第三题
This commit is contained in:
@@ -41,5 +41,5 @@
|
||||
|
||||

|
||||
|
||||
测试通过会会给出接下来的迷题位置,也可以在 [目录测试类](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)
|
||||
|
||||
+26
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user