Skip to content

Instantly share code, notes, and snippets.

@Eladkay
Last active August 6, 2021 20:24
Show Gist options
  • Save Eladkay/9ee28661b90d7cc14f6c990713c377dd to your computer and use it in GitHub Desktop.
Save Eladkay/9ee28661b90d7cc14f6c990713c377dd to your computer and use it in GitHub Desktop.
I needed it, so I made it. It takes two sets of lines and merges them alternatingly.
import java.util.*
fun main() {
val scanner = Scanner(System.`in`)
var last = ""
val lines1 = mutableListOf<String>()
do {
last = scanner.nextLine()
lines1.add(last)
} while (last != "$")
println("Size: ${lines1.size}")
val lines2 = mutableListOf<String>()
do {
last = scanner.nextLine()
lines2.add(last)
} while (last != "$")
println(lines1.mapIndexed { i, s -> "$s\n${if(lines2.size <= i) "" else lines2[i]}" }.filterNot { "$" in it }.joinToString("\n"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment