DEV Community


Discussion on: Daily Challenge #299 - Time to Grille!

celyes profile image
Ilyes Chouia

This is the solution in PHP, but I'm not sure if it's 100% correct since there aren't enough test cases and the test cases provided above don't have the result so they're pretty much useless.
anyway, here's my attempt:

function grille($message, $code)
    $letters = '';
    $code = array_filter(str_split(sprintf("%06d", decbin($code))), function($x) {
        return $x == 1;
    $code = array_keys($code);
    foreach(str_split($message) as $index => $letter){
        if(in_array($index, $code)){
            $letters .= $letter;
    return $letters;
Enter fullscreen mode Exit fullscreen mode