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.159 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.158 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.157 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.156 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.155 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.154 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.153 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.152 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.151 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.150 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.149 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.148 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.147 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.146 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.145 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.144 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.143 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.142 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.141 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.140 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt