import com.sun.org.apache.xpath.internal.operations.Bool
import java.util.*

object HandshakeCalculator {
    fun calculateHandshake(x: Int): List<Signal>{
        val temp: List<Boolean> = x.toBooleanList()
        val returnList = mutableListOf<Signal>()
        if (temp.getOrElse(0, {false})){
            returnList.add(Signal.WINK)
        }
        if (temp.getOrElse(1, {false})){
            returnList.add(Signal.DOUBLE_BLINK)
        }
        if (temp.getOrElse(2, {false})){
            returnList.add(Signal.CLOSE_YOUR_EYES)
        }
        if (temp.getOrElse(3, {false})){
            returnList.add(Signal.JUMP)
        }
        if (temp.getOrElse(4, {false})){
            returnList.reverse()
        }
        return returnList
    }
}

fun Int.toBooleanList(): List<Boolean>{
    val temp = Integer.toBinaryString(this).reversed()
    val returnArray = mutableListOf<Boolean>()
    for (i in temp){
        when (i.toInt()) {
            49 -> returnArray.add(true)
            else -> returnArray.add(false)
        }
    }
    return returnArray
}