Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Make this work (without using any built-in functions, only a for loop, return the next binary number in a string or as an array).
- // next_binary_number([1,0]) // [1,1]
- // possible test cases:
- // [1,0] => [1,1]
- // [1,1] => [1,0,0]
- // [1,1,0] => [1,1,1]
- // .......
- // [1,0,0,0,0,0,0,0,0,1] => [1,0,0,0,0,0,0,0,1,0]
- // Your solution:
- // if we type in our console your function and next_binary_number([1,0,0,0,0,0,0,0,0,1]) then the result should look like 1,0,0,0,0,0,0,0,1,0 (or as an array).
- function nextGreater($num) {
- $l = strlen($num);
- for ($i = $l - 1; $i >= 0; $i--)
- {
- if ($num[$i] == '0')
- {
- $num[$i] = '1';
- break;
- }
- else
- $num[$i] = '0';
- }
- if ($i < 0)
- $num = "1" . $num;
- return $num;
- }
- ?>
- <?php
- // Task 2:
- //
- // Make this work (no vowels, lowercase except the first letter):
- //
- // reformat("TyPEqaSt DeveLoper TeST") //Typqst dvlpr tst
- //
- // Your solution:
- //
- // if we type in our CLI your function and reformat("TyPEqaSr DeveLoper TeST") then the result should be Typqst dvlpr tst
- function reformat(string $sentance) {
- $vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"];
- $result = str_replace($vowels, "", ucfirst(strtolower($sentance)));
- return $result;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement