/ Learning to code

10 Advanced Ruby Code Challenges

It doesn’t matter if you’re just learning how to code or if you’re a seasoned programmer, solving code challenges is a great way to sharpen your skills. Not only will they help you learn more about coding, but they’re a standard part of technical interviews, so being comfortable solving code challenges can give you a competitive edge over the competition. But these aren’t the only reasons to test yourself with code challenges.

Another reason is to put the knowledge you gained through online coding courses and books to use. Coding is a skill that requires practice, and code challenges are a great way to use your coding skills. They provide a quick way to learn the concepts you’ll use later throughout your career.

But code challenges can also be fun. Conquering a complex problem is very rewarding. In this article, we have 10 advanced Ruby code challenges to get you started. Try a few today and come back later to complete the rest. If you get through all of these, we show you how to find more at the end of the article.

10 code challenges for experienced Ruby developers

So let's get started. To complete these code challenges, you’ll need in-depth knowledge of the Ruby programming language. There are many reasons to learn Ruby if you don't already know the language. To get started learning Ruby or refresh your skills, take our Learn Ruby course.

1. Re-inventing multiplication

In this challenge, write a function in Ruby that takes two parameters, both of them are numbers. The function should multiply the numbers and return the result, but there’s a catch. You’re not allowed to use the * symbol.

2. Calculate a javelin throw

In this challenge, you’ll calculate a trajectory.

Create a Ruby function that takes two parameters. The first parameter will be the initial speed of the javelin in meters per second. The second parameter will be the angle the javelin was thrown in degrees.

The function should return the maximum height that the javelin will reach and the maximum range of the javelin as a string. Results should be rounded to the nearest whole number. To help with your calculations, gravitational acceleration is 9.81 meters per second.

3. Calculate the bonus

A certain business that provides professional services charges their customers based on the person-days their staff works. This business also created a bonus system to reward and motivate the team to work harder.

They pay a bonus for each day a staff member worked for a client over a threshold target. The target threshold for a staff member is to bill 32 days out of the quarter. Here’s the breakdown of the bonus schedule:

  • 0 to 32 days: $0
  • 33 to 40 days: $365 per day
  • 41 to 48 days: $525 per day
  • More than 48 days: $625 per day

These bonuses are also calculated progressively.

Here’s an example of how the bonus would be calculated for an employee that worked 44 days in a quarter:

320 + 8365 + 4*625

Write a function in Ruby that accepts the number of days that an employee worked in a quarter and returns the bonus the employee will get.

4. Recursively reverse a string

For this challenge, write a Ruby function that accepts a string as a parameter and returns the string reversed. This would be easy to write, but for this challenge, you have to use recursion.

5. Map the letters of a string

For this challenge, you’ll need to write a function that accepts a word as a parameter. The function should return a hash that stores the indexes of each letter in an array. For example, if the parameter is 'dodo,' the function should return "{ :d=>[0, 2], :o=>[1, 3] }".

6. Count the arguments

Write a function in Ruby that accepts an unlimited number of arguments and returns the count of those arguments. This challenge may seem simple at first, but you really have to know Ruby to complete it.

7. Is it a new number?

A new number is defined as a number that is not a permutation of any smaller number. For example, 859 is not a new number because both 589 and 598 are smaller than it.

Leading zeroes don't count, so 30 is a new number. Write a function that accepts an integer as an argument and returns true if it’s a new number and false if it’s not.

8. Create a custom subtraction function

For this challenge, create a Ruby function that accepts two positive integer arguments. The function should subtract the second argument from the first.

The catch is that you can’t use any of the common mathematical operators. This includes -, %, /, *, or +. But, you can use any of the bitwise operators, including <<, |, ~, and &.

9. Poker hand ranking

Write a function in Ruby that accepts five arguments that represent five cards. Each card will be represented by two characters. The first character is the value of the card: 2-9, A, K, Q, and J. The second character is the suit: h, s, d, and c.

The function should return the Poker combination the hand contains. Return values include royal flush, straight flush, four of a kind, full house, flush, straight, three of a kind, two pair, pair, and high card. It should return the highest-ranked combination only.

10. Sum of digits

Write a function in Ruby that accepts two integers as arguments. The function should sum all the integers from the lowest parameter to the highest one.

For example, if the two arguments are 1 and 10, the function should return 55, which is 1+2+3+4+5+6+7+8+9+10.

Build your Ruby and code challenge skills

So, how did you like these challenges? If they made you want to check out more, then we have even more challenges for you.

You can sign up here or download our app and participate in our daily and weekly code challenges to help keep your programming skills sharp. You can also check out some of the past coding challenges in our code challenge forum.

If you’re new to the Ruby programming language or want to expand your skills in Ruby to tackle advanced code challenges like those above, our Learn Ruby course will teach you what you need to know. And, if you find out you really like Ruby, check out Learn Ruby on Rails and Learn Authentication in Ruby on Rails. These two courses will teach you how to use Ruby's famous framework to build web apps quickly and easily, just one of the many things Ruby is used for.


Ruby Courses & Tutorials | Codecademy
Ruby is a dynamic, general-purpose programming language most commonly used for Web Development. Its key designer, Yukihiro Matsumoto, said that Ruby was designed for humans, not machines, making it a favorite of many developers and tech companies. Its most popular implementation is with the powerful…

Get more practice, more projects, and more guidance.

Stephan Miller

Stephan Miller

Stephan Miller has been a full-stack, mobile, and machine learning developer for two decades and has written code for companies both big and small, both startups and established businesses.

Read More
10 Advanced Ruby Code Challenges
Share this