This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args : Array<String>) { | |
println("abc".generatePermutations()) | |
} | |
fun StringBuilder.generatePermutations(start: Int = 0, finish: Int = length-1, | |
result: MutableSet<String> = HashSet()) : Set<String> { | |
if(start == finish) | |
result.add(String(this)) | |
else | |
for(i in start .. finish) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args : Array<String>) { | |
println("A man, a plan, a canal, Panama!".isContainsPalindrome()) | |
} | |
fun String.isContainsPalindrome(): Boolean { | |
// handel edge cases | |
if(length == 0) | |
return false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package quicksort | |
import java.util.Collections | |
fun main(args : Array<String>) { | |
val list = "abcdefghijklmnopqrstuvwxyz".toMutableList() | |
Collections.shuffle(list) | |
println("before sort: $list") | |
list.quicksort() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package NearbyWords | |
import java.util.LinkedList | |
import kotlin.collections.HashSet | |
typealias CharSet = MutableFifthly<Set<Char>, Iterator<Char>, Char?, Long, Long> | |
class MutableFifthly<A, B, C, D, E>( | |
var first: A, | |
var second: B, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package NearbyWordsAlt | |
import kotlin.collections.HashSet | |
fun main(args : Array<String>) { | |
println(nearbyWords("gi")) | |
} | |
fun getAllWordPermutations(word: String): Set<String> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package NearbyWords | |
import kotlin.collections.HashSet | |
fun main(args : Array<String>) { | |
println(nearbyWords("gi")) | |
} | |
fun nearbyWords(word: String): Set<String> { | |
val permutations = getAllWordPermutations(word, 0) |
NewerOlder