Continued fraction/Arithmetic/Construct from rational number: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: hlint, hindent, added output section)
(→‎{{header|Kotlin}}: Updated example see https://github.com/dkandalov/rosettacode-kotlin for details)
Line 696: Line 696:
// compile with -Xcoroutines=enable flag from command line
// compile with -Xcoroutines=enable flag from command line


import kotlin.coroutines.experimental.*
import kotlin.coroutines.experimental.buildSequence


fun r2cf(frac: Pair<Int, Int>) =
fun r2cf(frac: Pair<Int, Int>) =
buildSequence {
buildSequence {
var num = frac.first
var num = frac.first
Line 723: Line 723:
}
}
val root2 = arrayOf(14142 to 10000, 141421 to 100000,
val root2 = arrayOf(14142 to 10000, 141421 to 100000,
1414214 to 1000000, 14142136 to 10000000)
1414214 to 1000000, 14142136 to 10000000)
println("\nSqrt(2) ->")
println("\nSqrt(2) ->")
for (frac in root2) {
for (frac in root2) {
Line 729: Line 729:
iterate(r2cf(frac))
iterate(r2cf(frac))
}
}
var pi = arrayOf(31 to 10, 314 to 100, 3142 to 1000, 31428 to 10000,
val pi = arrayOf(31 to 10, 314 to 100, 3142 to 1000, 31428 to 10000,
314285 to 100000, 3142857 to 1000000,
314285 to 100000, 3142857 to 1000000,
31428571 to 10000000, 314285714 to 100000000)
31428571 to 10000000, 314285714 to 100000000)