Math Help

What are all of the combinations I make with three single digit numbers. Each digit is between 1-8 (1 and 8 are included). Within the combination, each number is different (1,2,6) and does not repeat within the combination.

Also, if a combination is rearranged, it won't be included. Ex: if combination 1 = (1,2,6), combinations (1,6,2),(6,1,2),(2,6,1), etc wouldn't be included. Thanks for any help!

Comments

  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    @tglessy
    What are all of the combinations I make with three single digit numbers. Each digit is between 1-8 (1 and 8 are included). Within the combination, each number is different (1,2,6) and does not repeat within the combination.
    336
    Also, if a combination is rearranged, it won't be included. Ex: if combination 1 = (1,2,6), combinations (1,6,2),(6,1,2),(2,6,1), etc wouldn't be included. Thanks for any help!
    56
  • selectsoftselectsoft Member, PRO Posts: 38
    Just in case...

    Sounds like you're doing some random order stuff with a sequential number set. This may be of some help to you:

    http://www.ezinterweb.com/2013/03/fisher-yates-in-place-shuffle-for_18.html
  • tglessytglessy Member Posts: 41
    Thanks guys! Im being lazy about this, but is there a calculator of sorts that will give me all 336 combinations in a list?
  • tglessytglessy Member Posts: 41
    Or just the 56 :)
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    Or just the 56 :)
    @tglessy

    1,2,3
    1,2,4
    1,2,5
    1,2,6
    1,2,7
    1,2,8
    1,3,4
    1,3,5
    1,3,6
    1,3,7
    1,3,8
    1,4,5
    1,4,6
    1,4,7
    1,4,8
    1,5,6
    1,5,7
    1,5,8
    1,6,7
    1,6,8
    1,7,8
    2,3,4
    2,3,5
    2,3,6
    2,3,7
    2,3,8
    2,4,5
    2,4,6
    2,4,7
    2,4,8
    2,5,6
    2,5,7
    2,5,8
    2,6,7
    2,6,8
    2,7,8
    3,4,5
    3,4,6
    3,4,7
    3,4,8
    3,5,6
    3,5,7
    3,5,8
    3,6,7
    3,6,8
    3,7,8
    4,5,6
    4,5,7
    4,5,8
    4,6,7
    4,6,8
    4,7,8
    5,6,7
    5,6,8
    5,7,8
    6,7,8
  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143
    edited April 2013
    I wrote a little Lua program you can use to compute the answer too. I do love me some code!

    local TotalNumbers = 0 for a=1,8,1 do for b=a+1,8,1 do for c=b+1,8,1 do local Number = a*100 + b*10 + c print(Number) TotalNumbers = TotalNumbers + 1 end end end print("\n"..TotalNumbers.." combinations")

    The program output is:

    123 124 125 126 127 128 134 135 136 137 138 145 146 147 148 156 157 158 167 168 178 234 235 236 237 238 245 246 247 248 256 257 258 267 268 278 345 346 347 348 356 357 358 367 368 378 456 457 458 467 468 478 567 568 578 678 56 combinations

    You can paste that code into the form here to test it out: http://www.lua.org/cgi-bin/demo

    Exactly like Socks! We got the same answer! :P
  • SolarPepperStudiosSolarPepperStudios Member Posts: 754
    @CodeWizard Wow... You really are a code wizard! :D It would have taken me an entire day to even write that in Basic V.1!
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    I wrote a little Lua program you can use to compute the answer too. I do love me some code!
    @CodeWizard

    I used my Lua-Free engine and my digital input device (10bit).

    ;)
  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143
    @Socks
    Nice! :D
  • tglessytglessy Member Posts: 41
    I love you guys! Thanks!
  • tglessytglessy Member Posts: 41
    @CodeWizard how would you modify it for larger or smaller combinations? Like a 5 or 6 single digit combo?
  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143
    Can you elaborate on what you mean?
  • tglessytglessy Member Posts: 41
    @CodeWizard like right now, combos are made up of 3 single digits (1,2,3). Could your program be modified for bigger combinations (1,2,3,4), (1,2,3,4,5), etc within the same rules I have before? (1-8, no repeated numbers, etc)
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    @CodeWizard like right now, combos are made up of 3 single digits (1,2,3). Could your program be modified for bigger combinations (1,2,3,4), (1,2,3,4,5), etc within the same rules I have before? (1-8, no repeated numbers, etc)
    Yes it can.

    :)
  • SocksSocks London, UK.Member Posts: 12,822
    edited April 2013
    @CodeWizard

    Would 4 digits look like this (guess work, be kind :)) )

    for a=1,8,1 do
    for b=a+1,8,1 do
    for c=b+1,8,1 do
    for d=c+1,8,1 do
    local Number = a*1000 + b*100 + c*10 + d
    print(Number)
    TotalNumbers = TotalNumbers + 1
    end
    end
    end
    end
  • tglessytglessy Member Posts: 41
    @Socks when I looked at it, that's what I was thinking!
  • SocksSocks London, UK.Member Posts: 12,822
    @Socks when I looked at it, that's what I was thinking!
    That proves it, this programming stuff is easy, I'm off to start up my own global software empire (for the first few years we might be limited to lists of numbers).
  • JSprojectJSproject Member Posts: 730
    edited April 2013
    And since you wanted 5 combos too (yes, I've had a drink ;)

    local TotalNumbers = 0 for OneLittleCat=1,8,1 do for LikedToDance=OneLittleCat+1,8,1 do for ItBecameVeryFitCauseIt=LikedToDance+1,8,1 do for CauseItEnjoyedDancingSoMuch=ItBecameVeryFitCauseIt+1,8,1 do for AndItLivedHappyEveryAfter=CauseItEnjoyedDancingSoMuch+1,8,1 do local Number = OneLittleCat*10000 + LikedToDance*1000 + ItBecameVeryFitCauseIt*100 + CauseItEnjoyedDancingSoMuch*10 + AndItLivedHappyEveryAfter print(Number) TotalNumbers = TotalNumbers + 1 end end end end end

    ...and this is why i dont code ;)
  • CodeWizardCodeWizard Inactive, Chef Emeritus Posts: 1,143
    edited April 2013
    Here's a new version that uses code generation to compute the final value. Have fun with that:

    -- SNICHOLS: tweak these three variables to control the generator local MinNumber = 1 local MaxNumber = 8 local NumDigits = 3 -- SNICHOLS: generate some code to make the numbers local GeneratedCode = "" GeneratedCode = GeneratedCode.."local MinNumber="..MinNumber.." " GeneratedCode = GeneratedCode.."local MaxNumber="..MaxNumber.." " GeneratedCode = GeneratedCode.."local NumDigits="..NumDigits.." " GeneratedCode = GeneratedCode.."local Combinations=0 " GeneratedCode = GeneratedCode.."for d1=MinNumber,MaxNumber,1 do " for Index=2,NumDigits,1 do GeneratedCode = GeneratedCode.."for d"..Index.."=d"..(Index-1).."+1,MaxNumber,1 do " end GeneratedCode = GeneratedCode.."local Number = " for Index=NumDigits,1,-1 do GeneratedCode = GeneratedCode.."d"..Index.."*"..math.pow(10,Index-1).."+" end GeneratedCode = GeneratedCode.."0 print(Number) Combinations = Combinations + 1 " for Index=1,NumDigits,1 do GeneratedCode = GeneratedCode.."end " end GeneratedCode = GeneratedCode..[[print("\n"..Combinations.." combinations") ]] print("Generated Code:\n") print(GeneratedCode) print("\nOutput:\n") loadstring(GeneratedCode)()

    Output for the original data:

    Generated Code: local MinNumber=1 local MaxNumber=8 local NumDigits=3 local Combinations=0 for d1=MinNumber,MaxNumber,1 do for d2=d1+1,MaxNumber,1 do for d3=d2+1,MaxNumber,1 do local Number = d3*100+d2*10+d1*1+0 print(Number) Combinations = Combinations + 1 end end end print("\n"..Combinations.." combinations") Output: 321 421 521 621 721 821 431 531 631 731 831 541 641 741 841 651 751 851 761 861 871 432 532 632 732 832 542 642 742 842 652 752 852 762 862 872 543 643 743 843 653 753 853 763 863 873 654 754 854 764 864 874 765 865 875 876 56 combinations

    Interestingly enough, you can't go higher than 9 digits without it breaking. Makes sense based on your rules. Fun times!
  • tglessytglessy Member Posts: 41
    You make it seem so easy...much love everyone!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    For 8 numbers picking 3 with no repeats and no specific order, the total number of permutations is

    8!/(3!*(8-3)!) = 8*7*6*5*4*3*2*1/(3*2*1*5*4*3*2*1) = 8*7*6/3*2 = 8*7 = 56.
  • tylerglessnertylerglessner Member Posts: 246
    @Codewizard this was a while back, so I dont remember how to use the code you provided above. This time, I have digits 1-7 (including 1 and 7) and need to find three digit combinations like above. What do I change?
Sign In or Register to comment.