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!
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
Return a Value from a Function Math
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.
- 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
Cameron Childres11,815 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 :)
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.