Non duplicate digits and arrangement puzzle

  • Thread starter Thread starter K Sengupta
  • Start date Start date
  • Tags Tags
    Puzzle
AI Thread Summary
The discussion centers around finding an 8-digit integer B, represented as PQRSTUVW, which meets specific divisibility conditions and contains distinct digits from 1 to 9. The integer must satisfy several divisibility rules: PQ by 2, PQR by 3, PQRS by 4, PQRST by 5, PQRSTU by 6, PQRSTUV by 7, and PQRSTUVW by 8. A participant shared a Python programming solution that efficiently explores potential values for B. The code uses a recursive function to generate numbers while ensuring the digits remain distinct. A key line of code checks that the length of the set of digits equals 8, confirming the uniqueness of each digit in the number. The conversation highlights the challenge of the problem and the effectiveness of the programming approach used to solve it.
K Sengupta
Messages
113
Reaction score
0
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.
 
Physics news on Phys.org
Quasi-brute force...

38165472

DaveE
 
Using divisibility rules and after 6 pages of handwriting:
PQRSTUVW = 38165472
 
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:
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:
Hey mXSCNT,

your program looks compact. Can you explain it a little bit especially how you dealt with the digits being distinct?
 
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.
 
Just ONCE, I wanted to see a post titled Status Update that was not a blatant, annoying spam post by a new member. So here it is. Today was a good day here in Northern Wisconsin. Fall colors are here, no mosquitos, no deer flies, and mild temperature, so my morning run was unusually nice. Only two meetings today, and both went well. The deer that was road killed just down the road two weeks ago is now fully decomposed, so no more smell. Somebody has a spike buck skull for their...

Similar threads

Replies
1
Views
3K
Replies
3
Views
8K
Replies
2
Views
3K
2
Replies
67
Views
11K
Replies
8
Views
1K
3
Replies
100
Views
11K
Back
Top