DEV Community

Discussion on: Daily Challenge #193 - What's the Real Floor?

Collapse
 
vidit1999 profile image
Vidit Sarkar

C++ one liner

int getRealFloor(int americanFloor){
    // there is no 13th floor because of old superstitions, so no case of 13 and -13 is considered
    return (americanFloor<1) ? (americanFloor>=-12) ? americanFloor : americanFloor+1 : (americanFloor<=12) ? americanFloor-1 : americanFloor-2;
}

Here is what that thing actually is

if(americanFloor < 1){
    if(americanFloor >= -12)
        return americanFloor;
    else
        return americanFloor+1;
}
else{
    if(americanFloor <= 12)
        return americanFloor-1;
    else
        return americanFloor-2;
}