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 trialKarl Russell Sumando Menil
Full Stack JavaScript Techdegree Student 4,004 PointsReturn 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.
- Jab
- Right Cross or Straight right
- Left Hook
- Right Hook
- Left Uppercut
- 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
Karl Russell Sumando Menil
Full Stack JavaScript Techdegree Student 4,004 PointsBrandon White thank you sir for your clarification.
2 Answers
Cameron Childres
11,820 PointsHere'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 :)
Brandon White
Full Stack JavaScript Techdegree Graduate 35,454 PointsHi 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.
Karl Russell Sumando Menil
Full Stack JavaScript Techdegree Student 4,004 PointsKarl Russell Sumando Menil
Full Stack JavaScript Techdegree Student 4,004 PointsCameron 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.