60 likes | 161 Views
Project 2. Primary X- Subfactor Series. Factors. 6 {1, 2, 3, 6} 25 {1, 5, 25} 48 {1, 2, 3, 4, 6, 8, 12, 16, 24, 48} How do you tell if x is a factor of y ? (python) if y % x == 0: An inefficient way to get all the factors of y :
E N D
Project 2 Primary X-Subfactor Series
Factors • 6 {1, 2, 3, 6} • 25 {1, 5, 25} • 48 {1, 2, 3, 4, 6, 8, 12, 16, 24, 48} • How do you tell if x is a factor of y? • (python) if y % x == 0: • An inefficient way to get all the factors of y: • (python) filter(lambda x: y % x == 0, range(1, y+1))
Subsequences • Discard one or more digits, then leading zeros. • 1234: {123, 124, 134, 234, 12, 13, 14, 23, 24, 34, 1, 2, 3, 4} • 2004: {200, 204, 20, 24, 2, 4} • 7: {7} • How do you generate a list of all the subsequences of a number?
Subfactors • If a number x > 1 is both a factor of y and a subsequence of y, then it is a subfactor of y. • The only subfactor of 1234 is 2. • 6341 has none • 8013824 has {2, 4, 8, 13, 14, 32, 182, 832} • Once you’ve generated a list of subsequences, you can filter that list for factors, which gives you a list of subfactors.
X-Subfactor series • Start with a number. • Find a subfactor. • Produce a new number by x-ing (discarding) the digits of the subfactor from the original number. • Continue this process until you reach a number with no subfactors. • 25 2 • 48 8 • 48 4 • 111111 111 • 111111 1111 11
Assignment • For a given number n, find the primary x-subfactor series. • Primary means either the series with the most numbers, or if there is a tie, the one with the smallest second number (ties continue to be broken by comparing the next number and taking the smallest).