Sha256: 2090bbf504e2cd5c1d2bb82acad28da6f06b12fcdf8bd5525edd6e614adc119d

Contents?: true

Size: 528 Bytes

Versions: 188

Compression:

Stored size: 528 Bytes

Contents

object HandshakeCalculator {

    private val REVERSE_SIGNALS_BIT_POSITION = 4

    fun calculateHandshake(number: Int): List<Signal> {
        val result = Signal.values().filter {
            signal -> isBitSet(signal.ordinal, number)
        }

        if (isBitSet(REVERSE_SIGNALS_BIT_POSITION, number)) {
            return result.asReversed()
        } else {
            return result
        }
    }

    private fun isBitSet(position: Int, number: Int): Boolean {
        return number shr position and 1 == 1
    }

}

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.18 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.17 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.16 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.15 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.14 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.13 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.12 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.11 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.10 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.9 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.8 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.7 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.6 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.5 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.4 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.3 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.2 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.1 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.0 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.0.6 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt