Ejemplo n.º 1
0
def xsort(p):
    mergesort.q = 0
    
    mergesort.mergeSort(p)
    return p
Ejemplo n.º 2
0
def ysort(p):
    mergesort.q = 1
    mergesort.mergeSort(p)
    return p
Ejemplo n.º 3
0
from mergesort import mergeSort

def getDivisors(n):
    s = 0
    i = 1
    divisors = []
    limit = ceil(sqrt(n))
    while i <= limit:
        if n % i == 0:
            if (int(n/i)) not in divisors:
                divisors.append(i)
        i += 1
    return divisors

total = 0
n = 1
while n < 10000:
    divisors = getDivisors(n)
    for divisor in divisors:
        digits = [int(d) for d in (str(divisor) + str(int(n/divisor)) + str(n))]
        digits = mergeSort(digits)
        if digits == list(range(1, 10)):
            print(n)
            total += n
            break
    
    n += 1

print(total)

Ejemplo n.º 4
0
from mergesort import mergeSort

charsUsed = ''
randChars = []
passcode = []

f = open('keylog.txt')
line = f.readline()
while line != '':
    charsUsed += line[0] + line[1] + line[2]
    randChars.append(line)
    line = f.readline()
charsUsed = list(charsUsed)

# Generate an array of all digits used in the passcode
charsUsed = mergeSort(charsUsed)
i = 0
length = len(charsUsed)
while i < length - 1:
    try:
        while charsUsed[i] == charsUsed[i+1]:
            del charsUsed[i+1]
            length -= 1
    except IndexError:
        pass
    i += 1

i = 0
s = []
while i < factorial(len(charsUsed)):
    # Find the largest index k s.t. charsUsed[k] < charsUsed[k+1]
Ejemplo n.º 5
0
#!/usr/bin/env python3
# Project Euler problem 52

from mergesort import mergeSort

n = 2
while True:
    print(n)
    isSolution = True

    digits = mergeSort([int(d) for d in str(n)])
    for factor in range(1, 7):
        test = mergeSort([int(d) for d in str(n*factor)])
        if digits != test: isSolution = False

    if isSolution:
        print(n)
        break

    n += 1

Ejemplo n.º 6
0
#!/usr/bin/env python3
# Project Euler problem 29

from mergesort import mergeSort

terms = []

for a in range(2, 101):
    for b in range(2, 101):
        terms.append(a**b)

terms = mergeSort(terms)
i = 0
while i < len(terms)-1:
    while terms[i] == terms[i+1]:
        del terms[i+1]
    i += 1

print(len(terms))