loading...

re: Daily Challenge #62 - Josephus Survivor VIEW POST

FULL DISCUSSION
 

C++

    constexpr auto Josephus = [](int max, int step, const auto fn){
        if(step == 2){
            return ~(1 << static_cast<int>(log2(max * 2))) & ((max << 1) | 1);
        }

        if(max == 1){
            return 1;
        }
        return (fn(max - 1, step, fn) + step - 1) % max + 1;
    };

Code of Conduct Report abuse