This file contains hidden or 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
| class controlled_exec: | |
| def __init__(self, some_value): | |
| self.some_value = some_value | |
| def __enter__(self): | |
| print('before exec') | |
| return self.some_value+1 | |
| def __exit__(self, type, value, traceback): |
This file contains hidden or 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 com.fk | |
| import io.reactivex.Observable | |
| import io.reactivex.subjects.PublishSubject | |
| import java.util.concurrent.TimeUnit | |
| fun main(vararg args: String) { | |
| val values = listOf("1", "2", "", "3", "4", "", "5") | |
| val publisher = PublishSubject.create<String>() | |
| publisher |
This file contains hidden or 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
| class IsomorphismAlg { | |
| /* | |
| * both strings should be composed by characters between A and Z | |
| * */ | |
| fun doIt(a: String, b: String): Boolean { | |
| fun Char.simpleIndex() = this.toUpperCase() - 'A' | |
| fun checkMapping(a: Int, b: Int, array: Array<Int>) = |
This file contains hidden or 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
| class AnagramAlg { | |
| /* | |
| * Strings of the same size composed by characters from A to Z | |
| * */ | |
| fun doIt(a: String, b: String): Boolean { | |
| fun Char.simpleIndex() = this.toUpperCase() - 'A' | |
| val array = Array(26) { 0 } |
This file contains hidden or 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
| class SubstringAlg { | |
| fun doIt(a: String): Int { | |
| fun Char.simpleIndex() = this.toUpperCase() - 'A' | |
| var length = 0 | |
| var topLength = 0 | |
| var array = Array(26) { -1 } |
This file contains hidden or 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
| class PalindromeAlg { | |
| fun doIt(a: String): Boolean { | |
| fun Char.validCharacter() = | |
| this in 'A'..'z' || this in '0'..'9' | |
| var indexA = 0 | |
| var indexB = a.length - 1 |
This file contains hidden or 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 com.fk.tycho | |
| class ArrayRotator { | |
| fun doIt(array: Array<Int>, steps: Int): Array<Int> { | |
| val result = Array(array.size) { 0 } | |
| (0 until array.size).forEach { index -> | |
| result[(index + steps) % array.size] = array[index] | |
| } | |
| return result |
This file contains hidden or 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
| class ArraySumAlg { | |
| fun doIt(array: Array<Int>, target: Int): Pair<Int, Int> { | |
| var first = 0 | |
| var second = 1 | |
| while (first < array.size-1) { | |
| while (second < array.size) { | |
| if (array[first] + array[second] == target) | |
| return Pair(first, second) |
This file contains hidden or 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 com.fk.tycho.array | |
| class ArrayLargestAlg { | |
| fun doIt(array: Array<Int>, kth: Int): Int { | |
| fun swap(a: Int, b: Int) { | |
| // showing off swapping values without a temp value | |
| array[a] = array[a] + array[b] | |
| array[b] = array[a] - array[b] |
This file contains hidden or 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
| class ArrayZigZagAlg { | |
| fun doIt(array: Array<Int>) { | |
| fun swap(i: Int, j: Int) { | |
| array[i] = array[i] + array[j] | |
| array[j] = array[i] - array[j] | |
| array[i] = array[i] - array[j] | |
| } |
OlderNewer