(kotlin) added day 2 part 2
This commit is contained in:
parent
1dbae76d06
commit
0e44cfeff1
|
@ -0,0 +1,28 @@
|
|||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
fun countDifferences(s1: String, s2: String): Int {
|
||||
var diffs = 0
|
||||
for (pair in s1 zip s2) {
|
||||
if (pair.first != pair.second) {
|
||||
diffs++
|
||||
}
|
||||
}
|
||||
return diffs
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val inputStream: InputStream = File("input").inputStream()
|
||||
val inputLines = inputStream.bufferedReader().use { it.readText() }.split("\n");
|
||||
for (line1 in inputLines) {
|
||||
for (line2 in inputLines) {
|
||||
if (countDifferences(line1, line2) == 1) {
|
||||
println(line1)
|
||||
println(line2)
|
||||
return
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
C IIII
|
||||
Go IIIII
|
||||
Kotlin IIIII
|
||||
Kotlin IIII
|
||||
Python IIIII
|
||||
Rust IIIII
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user