fun compute(str1: String, str2: String): Int {
if(str1.length != str2.length)
throw IllegalArgumentException("left and right strands must be of equal length.")
var ret = 0
for((x, y) in str1.zip(str2)) {
if(x != y)
ret++
}
return ret
}
fun main(){
val str1 = "GAGCCTACTAACGGGAT"
val str2 = "CATCGTAATGACGGCCT"
val hdist = compute(str1, str2)
println(str1)
println(str2)
println("Hamming distance: $hdist")
}
class Matrix(private val matrix: List<List<Int>>){
fun column(c: Int): IntArray {
val col= IntArray(matrix.size)
var cindex = 0
for (r in matrix){
col[cindex++] = r[c]
}
return col
}
fun row(r: Int): IntArray {
return matrix[r].toIntArray()
}
}
fun main(){
val m = listOf(
listOf(1, 2, 3),
listOf(9, 8, 7),
listOf(7, 7, 7)
)
val matrix = Matrix(m)
println("Rows:")
for (n in m.indices) {
val row = matrix.row(n)
println(Arrays.toString(row))
}
println("Columns:")
for (n in m.indices) {
val col = matrix.column(n)
println(Arrays.toString(col))
}
}
fun reverse(str: String): String {
val ret = StringBuilder()
for (c in str.indices){
ret.append(str[str.length - c - 1])
}
return ret.toString()
}
fun main(){
val m = "analisi"
val rev = reverse(m)
println("$m --> $rev")
}
data class Person(val name: String, val surname: String, val id: String)
fun main() {
var c: Int? = null
c!!.toString()
}
class Square() : Polygon {
override val sides: Int = 4
override var name: String = "square"
}