Esempio n. 1
0
def candidates_5(maxi, primes):
	for n, m in combinations(primes, 2):
		if n * m > maxi:
			continue
		phi = (n - 1) * (m - 1)
		if isPermutation(n * m, str(phi)):
			yield ((n * m) / phi, n * m, phi) 
Esempio n. 2
0
def candidates_2(maxi):
	result = []
	for n in range(1, maxi):
		p = phi(n)
		if isPermutation(n, str(p)):
			result.append((n / p, n))
	return result
Esempio n. 3
0
 def testIsPandigital(self):
     self.assertEqual(True, isPermutation(734289165), "with default value 123456789")
     self.assertEqual(False, isPermutation(73489165), "with default value 123456789")
     self.assertEqual(False, isPermutation(774289165), "with default value 123456789")
     
     self.assertEqual(True, isPermutation(123, "123"))
     self.assertEqual(False, isPermutation(13, "123"))
     self.assertEqual(False, isPermutation(13, ""))
     
     self.assertEqual(False, isPermutation(133, "123"))
     self.assertEqual(False, isPermutation(123, "122"))
Esempio n. 4
0
def candidates_4(maxi):
	n2phi = {}
	
	primes = getPrimes(maxi)
	for p in primes:
		n2phi[p] = p - 1	
	for n, m in combinations(primes, 2):
		if n * m < maxi:
			n2phi[n * m] = n2phi[n] * n2phi[m]
	return [(n / p, n) for n, p in n2phi.items() if isPermutation(n, str(p))]		
Esempio n. 5
0
def candidates_3(maxi):
	n2phi = {}
	
	primes = getPrimes(maxi)
	for p in primes:
		n2phi[p] = p - 1	
	for n, m in combinations(primes, 2):
		if n * m < maxi:
			n2phi[n * m] = n2phi[n] * n2phi[m]
	
	for n in range(2, maxi):
		if not n in n2phi.keys():
			n2phi[n] = phi(n)
			if n % 2 == 0:
				fact = 2
				m = fact * n
				while m <= maxi:
					n2phi[m] = fact * n2phi[n]
					fact *= 2
					m = fact * n
	return [(n / p, n) for n, p in n2phi.items() if isPermutation(n, str(p))]		
Esempio n. 6
0
'''

The cube, 41063625 (345**3), can be permuted to produce two other cubes: 56623104 
(384**3) and 66430125 (405**3). In fact, 41063625 is the smallest cube which has 
exactly three permutations of its digits which are also cube. 

Find the smallest cube for which exactly five permutations of its digits are 
cube. 

'''
from utilities.specialNumbers import isPermutation

def getCandidate(start):
	n = start
	while len(str(n ** 3)) == len(str(start ** 3)):
		yield (n ** 3, n)
		n += 1

if __name__ == '__main__':
	print(10002 ** 3)
	for n in range(405, 100000):
		candidates = list(getCandidate(n))
		filteredCandidates = [c for c in candidates[1:] if isPermutation(c[0], str(candidates[0][0]))]
		if(len(filteredCandidates) == 4):
			print(candidates[0], filteredCandidates)
Esempio n. 7
0
'''
Take the number 192 and multiply it by each of 1, 2, and 3:

    192 × 1 = 192
    192 × 2 = 384
    192 × 3 = 576

By concatenating each product we get the 1 to 9 pandigital, 192384576. 
We will call 192384576 the concatenated product of 192 and (1,2,3)

The same can be achieved by starting with 9 and multiplying by 1, 2, 3, 4, and 5, 
giving the pandigital, 918273645, which is the concatenated product of 9 and (1,2,3,4,5).

What is the largest 1 to 9 pandigital 9-digit number that can be formed as the concatenated product 
of an integer with (1,2, ... , n) where n > 1?

'''
from utilities.specialNumbers import isPermutation

NUMBERS = "123456789"

if __name__ == '__main__':
    print([str(x) + str(2 * x) for x in range(9183, 10000) if isPermutation(int(str(x) + str(2 * x)), NUMBERS)])
Esempio n. 8
0
def foursHasProperty(x):
	return all([isPermutation(i * x, encryptedChars=str(x)) for i in range(2, 7)])
Esempio n. 9
0
'''
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, 
is 1 through 5 pandigital.

The product 7254 is unusual, as the identity, 39 × 186 = 7254, 
containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written 
as a 1 through 9 pandigital.
HINT: Some products can be obtained in more than one way so be sure to only include 
it once in your sum.
'''
from utilities.specialNumbers import isPermutation

def myConcat(a, b):
    return int(str(a) + str(b) + str(a * b))

if __name__ == '__main__':
    oneXfour = [(a, b, a * b) for a in range(1, 10) for b in range(1000, 10000) if isPermutation(myConcat(a, b))]
    twoXthree = [(a, b, a * b) for a in range(10, 100) for b in range(100, 1000) if isPermutation(myConcat(a, b))]
    print(oneXfour)
    print (len([t[2] for t in oneXfour + twoXthree]), len(set([t[2] for t in oneXfour + twoXthree])),
           sum(set([t[2] for t in oneXfour + twoXthree])))
    print([t[2] for t in oneXfour + twoXthree]) 
Esempio n. 10
0
def foursHasProperty(x):
	s = str(x)
	return isPermutation(x + 3330, s) and isPermutation(x + 2 * 3330, s) \
		and isPrime(x) and isPrime(x + 3330) and isPrime(x + 2 * 3330)
Esempio n. 11
0
def candidates_1(maxi):
	return [(n / phi(n), n) for n in range(1, maxi) if isPermutation(n, str(phi(n)))]