Skip to content

87-Ruby exercises/tests - CodeWars - archive (TOTAL SOLUTIONS -- 87-Ruby, 40-JavaScript, 28-Python, 25-PHP) (RANK -- 90th percentile)

Notifications You must be signed in to change notification settings

DanielGriffiths1182/ruby-codewars-archive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 

Repository files navigation

#CodeWars Review#

Archive of completed CodeWars exercises, language - Ruby

Short description and number in chronological order.

  • 1 Remove vowels from object (string)

  • 2 Return the shortest string in object (array)

  • 3 "Breaking chocolate pieces", algorithm. How many times do you have to break the "chocolate bar" for grid dimensions x, y

  • 4 Return integers in object (array) in descending order

  • 5 Write a function, persistence, that takes in a positive parameter num and returns its multiplicative persistence, which is the number of times you must multiply the digits in num until you reach a single digit

  • 6 Return the sum of the two smallest integers in object (array)

  • 7 Reject all array elements (string (names)) that don't have a length of four

  • 8 Write an algorithm that determines whether or not an object (integer) is a prime number

  • 9 Return an array of all divisors of integer (n), except 1 and (n)

  • 10 Return the sum of the multiples of 3 and 5 up to integer (n)

  • 11 Write a function that will find all the anagrams of a word from a list. You will be given two inputs a word and an array with words. You should return an array of all the anagrams or an empty array if there are none.

  • 12 Write an algorithm that returns, from an object (string), relationships of the like:(), ({}) is correct, (} is incorrect

  • 13 Write an algorithm that determines even or odd from a give object (integer)

  • 14 Count the number of times object (array) "hoola hoops", return concatenated string with answer

  • 15 Finding the next integer value for an array of integers when provided the average that needs to be attained by adding the next integer

  • 16 Return a list of integers 1..n where (n) is given

  • 17 Reverse words in a string and return a string (forgot split creates an array, was making nested arrays on accident)

  • 18 Provided these arguments integer integer and operator, which each have parameters, make it run... (.send is cool, just learned it)

  • 19 If object (string) is < 5 (integer) turn to 0. if object (string) > 5 and up, turn to 1

  • 20 How many 'bottles' do you have to buy to make the 'discount' worth it for the 'holiday'

  • 21 Picking flower petals, how much does she love you, she loves you not, etc...

  • 22 The tests are in such a form:

Test.assert_equals(remove("Hi!") , "Hi") Test.assert_equals(remove("Hi!!!") ,"Hi!!") Test.assert_equals(remove("!Hi") , "!Hi") Test.assert_equals(remove("!Hi!") , "!Hi") Test.assert_equals(remove("Hi! Hi!") , "Hi! Hi") Test.assert_equals(remove("Hi") , "Hi")

  • 23 Count positive numbers and sum negative numbers in object (array), and return [0][1]

  • 24 Replace all vowels in object (string) with '!'

  • 25 Return volume of a cube

  • 26 Remove smallest and largest values from object (array) and return the sum of whats left, clumsy first try

  • 27 Special answer for a special someone, concatenated string

  • 28 Return Celsius to Romer formula

  • 29 Return sqrt of object (integer)

  • 30 Take 2 strings and remove the non unique characters, then sort the new string alphabetically and return

(((Issue with test cases being incongruent with description, I noted on codewars)))

  • 31 Return first half of the letters of an object (string), but improved a little because of test case issue

  • 32 Return sum of positive integers in object (array), return 0 if empty

  • 33 Take a object (integer) and separate the digits, push into an array, in reversed order, return

  • 34 Change a negative object (integer) to its ABS, change positive integer to negative and return

  • 35 Create a string representing a dollar amount from an object (integer or float)

  • 36 Find minimum and maximum values in an object (array)

  • 37 Return (nth) digit of an object (object)

  • 38 Average of an object (array) of integers, returned as whole number

  • 39 Concat arrays, return sorted and unique values

  • 40 Remove all odd numbers from object (array)

  • 41 Delete every other element in object (array)

  • 42 Make sure the 'watermelon' can be divided so that each (2) people can have an even number of pieces, return

  • 43 Fix the operation so that it accurately calculates division, run function

  • 44 Multiply (n) by 5-raised to the power of the number of digits in (n), return integer

  • 45 Round down object (integer) with .floor

  • 46 Remove first and last element of an object (array)

  • 47 Remove the first character from object (string)

  • 47 Using MathPI, find circumference of a circle given parameters

  • 48 Given two points P and Q, output the symmetric point of point P about Q. Each argument is a two-element array of integers representing the point's X and Y coordinates. Output should be in the same format, giving the X and Y coordinates of point P1. You do not have to validate the input.

  • 49 This function should return the first pair of two prime numbers spaced with a gap of g between the limits m, n if these numbers exist otherwise nil or null or None or Nothing (depending on the language). In C++ return in such a case {0, 0}.

  • 50 Find the average between each index (integer) of object (array)

  • 51 Return the Barycenter of a triangle

  • 52 Find lowest integer that doesn't belong to object (array), greater than 0

  • 53 Find the number of times a character is repeated (char) in object (string)

  • 54 Find and print aspect ratio of any give two objects (integers)

  • 55 Given a string of integers, count how many times that integer repeats itself, then return a string showing the count and the integer. countMe('211213') will return '1221121113' (1 time 2, 2 times 1, 1 time 2, 1 time 1, 1 time 3)

  • 56 Find the maximum difference in length between 2 objets (strings) in 2 different (arrays)

  • 57 Finding approximate square roots. I couldn't figure out how to deal with rounding to different degrees per test.

  • 58 Calculate tips, object (r == three grades of quality of service ( 1 , 0 , -1)) and 20% tip as object

  • 59 Find min and max integers from a object (string) of integers

  • 60 Extract numbers from a object (string) and return the sum

  • 61 Count duplicate characters in object (string)

  • 62 Round numbers in object (array) to the nearest multiple of 5

  • 63 Reverse and invert all integer values in a given list.

Python:

reverse_invert([1 , 12 , 'a' , 3.4 , 87 , 99.9 , -42 , 50 , 5.6]) = [-1 , -21 , -78 , 24 , -5]

Ignore all other types than integer.

  • 64 To square(root) or not to square(root)

Write a method, that will get an integer array as parameter and will process every number from this array. Return a new array with processing every number of the input-array like this:

If the number has an integer square root, take this, otherwise square the number.

[ 4 , 3 , 9 , 7 , 2 , 1 ] -> [ 2 , 9 , 3 , 49 , 4 , 1 ] The input array will always contain only positive numbers and will never be empty or null.

The input array should not be modified!

Have fun coding it and please don't forget to vote and rank this kata! :-)

I have created other katas. Have a look if you like coding and challenges.

  • 65 Given a number, say prod (for product), we search two Fibonacci numbers F(n) and F(n+1) verifying

F(n) * F(n+1) = prod. Your function productFib takes an integer (prod) and returns an array:

[F(n), F(n+1), true] depending on the language if F(n) * F(n+1) = prod.

If you don't find two consecutive F(m) verifying F(m) * F(m+1) = prod you will return

[F(m), F(m+1), false] F(m) being the smallest one such as F(m) * F(m+1) > prod.

  • 66 Create function that takes one positive three digit integer and rearranges its digits to get maximum possible number. Assume that argument is integer. Return null (nil for ruby) if argument is not valid.

  • 67 You have to search all numbers from inclusive 1 to inclusive a given number x, that have the given digit d in it. The value of d will always be 0 - 9. The value of x will always be greater than 0.

You have to return as an array

the count of these numbers, their sum, and their product.

x = 11 d = 1 Numbers: 1, 10, 11 Return: [3, 22, 110]

  • 68 Write a function which removes from string all non-digit characters and parse the remaining to number. E.g: "hell5o wor6ld" -> 56

  • 69 Given a string containing a list of integers separated by commas, write the function string_to_int_list(s) that takes said string and returns a new list containing all integers present in the string, preserving the order.

  • 70 Find the last element of a list.

  • 71 A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. Allowances may be made for adjustments to capital letters, punctuation, and word dividers.

  • 72 You are going to be given a string. Your job is to return that string in a certain order that I will explain below:

Let's say you start with this: 012345

The first thing you do is reverse it: 543210 Then you will take the string from the 1st position and reverse it again: 501234 Then you will take the string from the 2nd position and reverse it again: 504321 Then you will take the string from the 3rd position and reverse it again: 504123

Continue this pattern until you have done every single position, and then you will return the string you have created. For this particular number, you would return: 504132

  • 73 We need a function that can transform a string into a number. (Thought I'd knock this out for some easy points)

  • 74 You start at the first number. If this number x is smaller than 3, take this number x direct for the new array and continue with the next number. If this number x is greater than 2, take the next x numbers (inclusive this number) as a sub-array in the new array. Continue with the next number AFTER this taken numbers. If there are too few numbers to take by number, take the last available numbers.

  • 75 (from CodeFights last month) Write a function that returns the century for the given year (round up if necessary).

  • 76 (from CodeFights last month) Write a function that checks whether input is a palindrome.

  • 77 You will be given two dimensions, imagine a rectangle, write an algorithm that returns in an array a list of
    SQUARES that == the area of the rectangle

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]

  • 78 Given array with False/True in every index, count the number of True cases in the array.

  • 79 Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love.

Write a function that will take the number of petals of each flower and return true if they are in love and false if they aren't.

  • 80 Positive integers that are divisible exactly by the sum of their digits are called Harshad numbers, see Wikipedia for further details. Write a function numberJoy() which tests if a positive integer n is Harshad and returns True if the product of its digit sum, and its digit sum reversed, equals n. Otherwise return False.

  • 81 "Identical Elements" - compare arrays, return boolean depending whether or not they contain any same values.

  • 82 "Plural" - We need a simple function that determines if a plural is needed or not. It should take a number, and return true if a plural should be used with that number or false if not. This would be useful when printing out a string such as 5 minutes, 14 apples, or 1 sun.

  • 83 "Sort and Star" - You will be given an vector of string(s). You must sort it alphabetically (case-sensitive!!)
    and then return the first value. The returned value must be a string, and have '*** ' between each of its letters.

  • 84 "Get list sum recursively" - Write function sumR which returns the sum of values in a given list. Try no to cheat and provide recursive solution.

  • 85 "Rearrange Number to Get its Maximum" - Create function that takes one positive three digit integer and rearranges its digits to get maximum possible number. Assume that argument is integer. Return null (nil for ruby) if argument is not valid.

  • 86 "Circle area inside square" - Turn an area of a square in to an area of a circle that fits perfectly inside the square.

  • 87 "The Mean of Two Means" - Write a function getMean that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array.

The mean should be computed if both x and y have values higher than 1 but less or equal to the array's length. Otherwise the function should return -1.

getMean([1,3,2,4], 2, 3) should return 2.5 because: the mean of the the first 2 elements of the array is (1+3)/2=2 and the mean of the last 3 elements of the array is (4+2+3)/3=3 so the mean of those 2 means is (2+3)/2=2.5.

getMean([1,3,2,4], 1, 2) should return -1 because x is not higher than 1.

getMean([1,3,2,4], 2, 8) should return -1 because 8 is higher than the array's length.

  • 88 (LVL 8) "Is Upcase" - Create a method is_uppercase() to see whether the string is ALL CAPS.

  • 89 (LVL 8) "Remove exclamation marks" - Write function RemoveExclamationMarks which removes all exclamation marks from a given string.

  • 90 (LVL 8) "Square(n) Sum" - Complete the squareSum method so that it squares each number passed into it and then sums the results together.

  • 91 (LVL 8) "Grasshopper - Basic Function Fixer" - I created this function to add five to any number that was passed in to it and return the new value. It doesn't throw any errors but it returns the wrong number.

Can you help me fix the function?

About

87-Ruby exercises/tests - CodeWars - archive (TOTAL SOLUTIONS -- 87-Ruby, 40-JavaScript, 28-Python, 25-PHP) (RANK -- 90th percentile)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages