Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Non duplicate digits and arrangement puzzle

  1. Jun 10, 2009 #1
    B is a positive 8-digit base ten integer of the form PQRSTUVW that contains precisely 8 distinct digits from 1 to 9, and satisfies all of the following conditions:

    (i) PQ is divisible by 2.
    (ii) PQR is divisible by 3.
    (iii) PQRS is divisible by 4.
    (iv) PQRST is divisible by 5.
    (v) PQRSTU is divisible by 6.
    (vi) PQRSTUV is divisible by 7.
    (vii) PQRSTUVW is divisible by 8.

    Determine all possible value(s) that B can assume.
     
  2. jcsd
  3. Jun 11, 2009 #2
    Quasi-brute force...

    38165472

    DaveE
     
  4. Aug 8, 2009 #3
    Using divisibility rules and after 6 pages of handwriting:
    PQRSTUVW = 38165472
     
  5. Aug 8, 2009 #4
    It was a fun little programming exercise to do it in an efficient way:
    12965408
    30925864
    36925840
    38165472
    72965480
    78320416
    78920456
    80165472
    92765408
    my Python:
    Code (Text):

    def finddigits2():
        def step(prefix,divisible):
            nextprefix = (prefix*10-1)/divisible*divisible
            while nextprefix < (prefix+1)*10-divisible:
                nextprefix += divisible
                if divisible < 8:
                    step(nextprefix,divisible+1)
                else:
                    if len(set(str(nextprefix))) == 8:
                        print nextprefix
        for f in range(1,10):
            step(f,2)
     
     
    Last edited: Aug 8, 2009
  6. Aug 8, 2009 #5
    Hey mXSCNT,

    your program looks compact. Can you explain it a little bit especially how you dealt with the digits being distinct?
     
  7. Aug 8, 2009 #6
    I dealt with that in this line:
    if len(set(str(nextprefix))) == 8:

    str(nextprefix) writes the prefix as a string, such as 12965408 becomes "12965408". set(str(nextprefix)) turns the individual characters in the string into a set (ignoring duplicates) so in this case that would be set(['1','2','9','6','5','4','0','8']). len(set(str(nextprefix))) == 8 checks that the "length" of the set (the number of elements in the set) is 8.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Non duplicate digits and arrangement puzzle
Loading...