Back to Blogs
#challenge

Jedi Training Challenge

Greetings, Jedi Padawans, fellow coders, and esteemed Jedi Knights. In the Star Wars universe, Jedi...

1 min read
Cover for Jedi Training Challenge

Greetings, Jedi Padawans, fellow coders, and esteemed Jedi Knights.

In the Star Wars universe, Jedi Knights are skilled in the use of the Force, a mystical energy that they can manipulate to achieve various abilities. In this coding challenge, we'll be simulating Jedi training by creating a program that generates a sequence of numbers and applies various transformations to them using...the power of code!

Instructions:

Write a program that generates a sequence of 10 random numbers between 1 and 10.
Use the Force (code) to apply the following transformations to the sequence:

  1. Multiply every even number by 2
  2. Add 5 to every odd number
  3. Replace any number greater than 10 with 1
  4. Print the final sequence to the console.

Example Output:
Image description

Hints:

  • You can use the rand method in Ruby or the random module in Python to generate random numbers.
  • You can use an if statement to check whether a number is even or odd.
  • You can use a for loop to iterate over the sequence and apply the transformations.

The challenge begins. May the fourth be with you!