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.58 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.57 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.56 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.55 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.54 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.53 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.52 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.51 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.50 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.49 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.48 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.47 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.46 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.45 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.44 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.43 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.42 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.41 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.40 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.39 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt