Puzzle - RPL and others
|
05-06-2021, 09:09 PM
Post: #29
|
|||
|
|||
RE: Puzzle - RPL and others
(05-05-2021 06:29 PM)Albert Chan Wrote: With this, I confirmed there is no solution for 16 ≤ n ≤ 44 I found out the reason n=42 take less time than n=40. Think non-buckets. Example, first digit does not belong to any buckets. >>> n = 10 # = 2 * 5 >>> sorted(set(range(1,n)) - set(range(2,n,2)) - set(range(5,n,5))) [1, 3, 7, 9] >>> n = 40 # = 2**3 * 5 >>> sorted(set(range(1,n)) - set(range(2,n,2)) - set(range(5,n,5))) [1, 3, 7, 9, 11, 13, 17, 19, 21, 23, 27, 29, 31, 33, 37, 39] >>> n = 42 # = 2 * 3 * 7 >>> sorted(set(range(1,n)) - set(range(2,n,2)) - set(range(3,n,3)) - set(range(7,n,7))) [1, 5, 11, 13, 17, 19, 23, 25, 29, 31, 37, 41] This is the set of digits for d1, and n=42 has less elements than n=40. (looping anything else is just a waste of time) And, this set applied not just d1, but any dk that is coprime to n. Conversely, if k is not coprime to n, dk must not be above sets of values. Combined, we have invariant: coprime(n,k) = coprime(n,dk) Code: from euclid import gcd I doubled up lst for 2 purpose. (lst combined to reduce stress of arguments passing) First half is to check duplicates, like before. Second half holds coprime(n,d) table: lst[n+d] ≡ coprime(n,d) Coprime test benefited if base n has many different factors. Code: time (sec), on my Toshiba A665 laptop |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)