DEV Community

Cover image for Jedi Training Challenge staff for The DEV Team

Posted on

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!


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


  • 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!

Top comments (8)

rainleander profile image
Rain Leander • Edited

Assuming that any number greater than 10 gets replaced with 1, I wrote up a little script, created a repository for it, and hereby present

I also wrote up a little response post - I hope that's oke!

kalkwst profile image
Kostas Kalafatis • Edited

Hey everyone! I wanted to encourage all the newcomers to give this challenge a shot. Don't worry if you're not an experienced developer yet, challenges like these are a great way to dip your feet into the field and learn some new skills. And who knows, you might surprise yourself with what you can come up with!

For those of you who are more seasoned devs, why not try out some whacky solutions and see what you can come up with?

I'm personally introducing my own overly-engineered solution to get your noggings churning!

Behold the Fully Realized And Needlessly Komplex Extension-based Numerical Sequence Transformation Engine Involving a Number builder or FRANKENSTEIN.

Let's all have some fun and challenge ourselves in new ways. Good luck, and happy coding!

namenotavilable profile image
Adam Markiewicz

import random

sequence = [random.randint(1, 10) for _ in range(10)]

for i in range(len(sequence)):
if sequence[i] % 2 == 0:
sequence[i] *= 2
sequence[i] += 5

if sequence[i] > 10:
sequence[i] = 1


siddharthshyniben profile image
Siddharth • Edited

I had to golf it :P
83 81 bytes:

Enter fullscreen mode Exit fullscreen mode

If anyone can go shorter I'd love to see it!

jonrandy profile image
Jon Randy 🎖️

Your transformed sequence is wrong according to the transformations, since it contains numbers greater than 10, which would be removed by step 3.

jonrandy profile image
Jon Randy 🎖️ • Edited

TBH, your instructions are extremely ambiguous and - unless I'm missing something, your sample output is not achievable using any interpretation of the instructions I can think of. Step 3 is the main offender here.

jonrandy profile image
Jon Randy 🎖️ • Edited

Unless we are supposed to do 1 or 2 or 3 based upon the original number - in which case 3 is never going to happen. Overall, a pretty poorly worded challenge to give to beginners.

mishmanners profile image
Michelle Duke

I think I got it right:

Someone tell me 😄