Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
import java.util.concurrent.SynchronousQueue
|
||||
import kotlin.concurrent.thread
|
||||
import java.io.File
|
||||
|
||||
const val EOT = "\u0004" // end of transmission
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val queue = SynchronousQueue<String>()
|
||||
|
||||
val work = thread {
|
||||
var count = 0
|
||||
|
||||
while (true) {
|
||||
val line = queue.take()
|
||||
if (line == EOT) {
|
||||
queue.put(count.toString())
|
||||
break
|
||||
}
|
||||
println(line)
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
File("input.txt").forEachLine { line -> queue.put(line) }
|
||||
queue.put(EOT)
|
||||
work.join()
|
||||
|
||||
val count = queue.take().toInt()
|
||||
println("\nNumber of lines printed = $count")
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// version 1.3.20 with kotlinx-coroutines-core version 1.1.1
|
||||
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.channels.sumBy
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import java.io.File
|
||||
|
||||
suspend fun main() {
|
||||
coroutineScope {
|
||||
val lines = Channel<String>()
|
||||
|
||||
val count = async {
|
||||
lines.sumBy { line ->
|
||||
println(line)
|
||||
1
|
||||
}
|
||||
}
|
||||
|
||||
File("input.txt").bufferedReader().forEachLine { line -> lines.send(line) }
|
||||
println("\nNumber of lines printed = ${count.await()}")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue