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.38 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.37 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.36 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.35 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.34 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.33 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.32 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.31 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.30 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.29 tracks/kotlin/exercises/secret-handshake/.meta/src/reference/kotlin/HandshakeCalculator.kt
trackler-2.2.1.28 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.27 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.26 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.25 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.24 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.23 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.22 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.21 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.20 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt
trackler-2.2.1.19 tracks/kotlin/exercises/secret-handshake/src/example/kotlin/HandshakeCalculator.kt