Advertisement
paranid5

std::pool

Jun 24th, 2021
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.58 KB | None | 0 0
  1. import java.io.File
  2. import java.util.concurrent.Executors
  3.  
  4. private fun Number.fib(): Number {
  5.     if (toLong() < 3)
  6.         return 1
  7.  
  8.     var f = 1
  9.     var s = 1
  10.     val numberLong = toLong()
  11.  
  12.     (3..numberLong).forEach { _ ->
  13.         val mem = s
  14.         s += f
  15.         f = mem
  16.     }
  17.  
  18.     return s
  19. }
  20.  
  21. fun main() {
  22.     print("Number of threads: ")
  23.     val executor = Executors.newFixedThreadPool(readLine()!!.toInt())
  24.  
  25.     File("file.txt").forEachLine {
  26.         executor.execute {
  27.             println(it.toInt().fib())
  28.         }
  29.     }
  30.  
  31.     executor.shutdown()
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement