Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Functions Create Reusable Code with Functions Return a Value from a Function

Return a Value from a Function Math

Good day,

i am currently boxing as my work out, my question is how do i generate all 6-number combinations of numbers 1,2,3,4,5,6?

Here are six boxing punches (right-handed or orthodox) every aspiring champion must learn.

  1. Jab
  2. Right Cross or Straight right
  3. Left Hook
  4. Right Hook
  5. Left Uppercut
  6. Right Uppercut

how do i right the code so that it will show me all the possible 6-digit combinations for all the punching combinations, but not repeating my calculations would be 6 x 6 = 36 combinations of non-repeating boxing punches, please correct me if i am wrong?

Best regards, Karl Russell

Cameron Childres thank you for your reply sir but i think we do not need to print 1-1-1-1-1-1, or any repeating number in the same sequence i am only looking for a code that will help me generate all 36 combinations because 6x6 is = 36. regards.

Brandon White thank you sir for your clarification.

2 Answers

Cameron Childres
Cameron Childres
11,817 Points

Here's an in-depth article that you might find useful, I came across it recently when trying to solve a similar problem. Word of warning -- for 6 characters you're looking at 6! = 720 permutations -- that's a whole lot of boxing :)

Hi Karl,

Based on your question Cameron is correct. Factorial is the method you would use to find all permutations.

Letโ€™s make the problem smaller so that itโ€™s easier to see. Say youโ€™re trying to find all unique three digit calculations for the numbers 1, 2, and 3. Based on your positioning 3x3 equals 9, but in fact there are only 6 possible permutations. They are: 123, 132, 213, 231, 312, and 321. 3! is 6. When you change the amount of numbers to 6, the equation changes to 6!, which does equate to 720. Itโ€™s hard to fathom (I know), but you can in fact get 720 unique six-digit numbers from the numbers 1, 2, 3, 4, 5, 6.