Archive of completed CodeWars exercises, languages - PHP
Short description and numbered in chronological order.
LEVEL => 8 = low, 1 = high, TITLE, DESCRIPTION
-
1 (LVL 8) "Volume of a Cuboid" - Give dimensions of cube, execute the proper operation to return volume.
-
2 (LVL 8) "Keep Hydrated!" - Because Nathan knows it is important to stay hydrated, he drinks 0.5 liters of water per hour of cycling. You get given the time and you need to return the number of liters Nathan will drink, rounded to the smallest value.
-
3 (LVL 8) "Even of Odd?" - Give an integer, return the string "Even" or the string "Odd" depending on the value of the integer.
-
4 (LVL 8) "Remove String Spaces" - Given a string, strip all whitespace and return.
-
5 (LVL 8) "Multiply" - (INSTRUCTIONS): The code does not execute properly. Try to figure out why. (SOLUTION): declare variables correctly, (;) at code blocks correctly.
-
6 (LVL 8) "Debug the functions EASY" - (INSTRUCTIONS): Given incorrect syntax, correct the syntax.
-
7 (LVL 8) "Calculate average" - Given an array of values, calculate the average. (I keep forgetting the ; after code)
-
8 (LVL 8) "Palindrome Strings" - Given string, write algorithm that returns boolean for "is it a Palindrome".
-
9 (LVL 7) "Sum up the random string" - Given string with letters and numbers, extract the numbers and return sum.
-
10 (LVL 8) "Opposite number" - Very simple, given a number, find its opposite.
-
11 (LVL 7) "Shortest Word" - x Simple, given a string of words, return the length of the shortest word(s). String will never be empty and you do not need to account for different data types.
-
12 (LVL 8) "Get the mean of an array" - It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the given array rounded down to its nearest integer. The array will never be empty.
-
13 (LVL 8) "Basic Mathematical Operations" - The function should take three arguments - operation(string/char), value1(number), value2(number). The function should return result of numbers after applying the chosen operation.
-
14 (LVL 8) "Sum of positive" - You get an array of numbers, return the sum of all of the positives ones.
-
15 (LVL 8) "Reversing Words in a String" - You need to write a function that reverses the words in a given string.
-
16 (LVL 8) "Find Maximum and Minimum Values of a List" - Your task is to make two functions, max and min (maximum and minimum in PHP) that take a(n) array/vector of integers list as input and outputs, respectively, the largest and lowest number in that array/vector.
-
17 (LVL 7) "Thinkful - Number Drills: Rømer temperature" - You're writing an excruciatingly detailed alternate history novel set in a world where Daniel Gabriel Fahrenheit was never born.
Since Fahrenheit never lived the world kept on using the Rømer scale, invented by fellow Dane Ole Rømer to this very day, skipping over the Fahrenheit and Celsius scales entirely.
Your magnum opus contains several thousand references to temperature, but those temperatures are all currently in degrees Celsius. You don't want to convert everything by hand, so you've decided to write a function, celsius_to_romer() that takes a temperature in degrees Celsius and returns the equivalent temperature in degrees Rømer.
For example: celsius_to_romer(24) should return 20.1.
- 18 (LVL 8) "Jenny's Secret Message" - Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake.
Can you help her?
-
19 (LVL 8) "Pre-FizzBuzz Workout 1" - This is the first step to understanding FizzBuzz. Your inputs: a positive integer, n, greater than or equal to one. n is provided, you have NO CONTROL over its value. Your expected outputs: an array of positive integers from 1 to n Your job is to write an algorithm that gets you from the input to the output.
-
20 (LVL 6) "Rectangle into Squares" - The drawing below gives an idea of how to cut a given "true" rectangle into squares ("true" rectangle meaning that the two dimensions are different).
Can you translate this drawing into an algorithm?
You will be given two dimensions
a positive integer length (parameter named lng) a positive integer width (parameter named wdth) You will return an array with the size of each of the squares.
sqInRect(5, 3) should return [3, 2, 1, 1] sqInRect(3, 5) should return [3, 2, 1, 1]
Note:
lng == wdth as a starting case would be an entirely different problem and the drawing is planned to be interpreted with lng != wdth. See kata, Square into Squares. Protect trees!.
When the initial parameters are so that lng == wdth, the solution [lng] would be the most obvious but not in the spirit of this kata so, in that case, return None/nil/null/Nothing. Return {} with C++.
In that case the returned structure of C will have its sz component equal to 0. (See the "Solution" and "Examples" tabs)
-
21 (LVL 8) "Remove exclamation marks" - Write a function that removes all exclamation marks from string.
-
22 (LVL 8) "Fake Binary" - Given a string of digits, you should replace any digit below 5 with '0' and any digit 5 and above with '1'. Return the resulting string.
-
23 (LVL 8) "How Many Lightsabers Do You Own?" - (NOTE: Added argument ='', to make pass) Inspired by the development team at Vooza, write the function howManyLightsabersDoYouOwn that accepts the name of a programmer, and returns the number of lightsabers owned by that person.
The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesome number of lightsabers. Anyone else owns 0.
No starting help here -- you'll need to know how to write a function that accepts a parameter and returns a value based on that parameter.
-
24 (LVL 8) "String Repeat" - Write a function that repeats a string n number of times.
-
25 (LVL 8) "Simple calculator" - NOTE: Better refactoring then last time using case blocks. / Write a function that takes a string operator and performs operations with it.