Created
July 5, 2017 19:38
-
-
Save 451F/9cf7510145cd23dd7fe7e9e7398f312b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $input_array = [ | |
| 'Hello World', | |
| 'lorem ipsum' | |
| ]; | |
| function reverse_line($line) { | |
| return implode(' ', array_reverse(explode(' ', $line))); | |
| } | |
| foreach ($input_array as $value) { | |
| var_dump(reverse_line($value)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $input = [ | |
| [2, 3, 8], | |
| [5, 3, 10] | |
| ]; | |
| function answers(array $numbers) { | |
| $line_result = ''; | |
| for ($i=1;$i<=$numbers[2];$i++) { | |
| if ($i % $numbers[0] === 0) { | |
| if ($i % $numbers[1] === 0) { | |
| $line_result.= ' pingpong'; | |
| } else { | |
| $line_result.= ' ping'; | |
| } | |
| } elseif ($i % $numbers[1] === 0) { | |
| $line_result.= ' pong'; | |
| } else { | |
| $line_result.= ' ' . (string) $i; | |
| } | |
| } | |
| return trim($line_result); | |
| } | |
| foreach ($input as $value) { | |
| var_dump(answers($value)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $input = [2, 3, 4, 5]; | |
| function bin_ones_sum($value) { | |
| $str_presentation = ''; | |
| for ($i=1;$i<=$value;$i++) { | |
| $str_presentation.= (string) decbin($i); | |
| } | |
| return substr_count(trim($str_presentation), '1'); | |
| } | |
| foreach ($input as $value) { | |
| var_dump(bin_ones_sum($value)); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment