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; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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: