コード例 #1
0
ファイル: main.py プロジェクト: h2oboi89/Euler
def main():
    prime_numbers = primes(18)

    s = 0
    for permutation in permute(list(range(10))):
        s += test_value(convert_to_strings(permutation), prime_numbers)

    return s
コード例 #2
0
ファイル: crunch.py プロジェクト: flowlo/pcp-vns
def permute (word):
	result = []
	if len(word) == 1:
		result.append(word)
	else:
		for pos in range(len(word)):
			permutations = permute(word[0:pos] + word[pos + 1:len(word)])
			for item in permutations:
				result.append(word[pos] + item)
	return result
コード例 #3
0
ファイル: main.py プロジェクト: h2oboi89/Euler
def main():
    limit = 9

    vals = list(range(1, limit + 1))
    sums = set()
    modes = [Mode.OneFour, Mode.TwoThree]

    for p in permute(vals):
        # only need to check 1 digit * 4 digit and 2 digit * 3 digits

        for mode in modes:
            a, b, c = permuteNumbers(p, mode)

            if a * b == c:
                if not c in sums:
                    sums.add(c)

    return sum(sums)
コード例 #4
0
ファイル: main.py プロジェクト: h2oboi89/Euler
def main():
    prime_numbers = primes(10000)

    prime_numbers = [p for p in prime_numbers if p > 999]

    permutations = []

    for p in prime_numbers:
        t = set() # numbers with non-unique digits should be ignored

        for perm in permute(p):
            i = int(''.join(map(str, perm)))

            if i < 1000:
                continue

            if is_prime(i):
                if i in prime_numbers:
                    prime_numbers.remove(i)
                t.add(i)

        if len(t) > 2:
            t = list(t)
            t.sort()
            permutations.append(t)

    j = 0
    for perm in permutations:
        t = set()
        for i in range(len(perm) - 1):
            for p in perm[i + 1:]:
                if p - perm[i] == 3330:
                    t.add(perm[i])
                    t.add(p)

        if len(t) == 3:
            if j == 1:
                return int(''.join(map(str, t)))
            j += 1
コード例 #5
0
ファイル: main.py プロジェクト: ieh333/Python
from time import *
from permute import *

str = input("Vavedete niz ot chisla:\n")
lst = list(str)
t1 = time()
l = permute(lst)
t2 = time()
t = t2 - t1
print(l)
print(t)
コード例 #6
0
ファイル: crunch.py プロジェクト: flowlo/pcp-vns
from subprocess import call
from sys import argv, exit

def permute (word):
	result = []
	if len(word) == 1:
		result.append(word)
	else:
		for pos in range(len(word)):
			permutations = permute(word[0:pos] + word[pos + 1:len(word)])
			for item in permutations:
				result.append(word[pos] + item)
	return result

args = '-s 10 -i 20 -u 1000 -t 600'

if len(sys.argv) < 5:
	print 'Usage: ' + argv[0] + ' <runs> <units> <outdir> <instances>'
	exit(0)

runs = int(argv[1])
permutations = permute(argv[2])
output = abspath(argv[3]) + '/'

for i in range(runs):
	mkdir(output + str(i))
	for n in argv[4:]:
		for p in permutations:
			base = output + '/' + str(i) + '/' + basename(n) + '.' + p
			call('./pcp ' + args + ' -n ' + p + ' < ' + n + ' > ' + base + '.json &', shell = True)
コード例 #7
0
ファイル: outputter.py プロジェクト: flowlo/pcp-vns
if len(argv) < 4:
    print "Usage: " + argv[0] + " <units> <runs> <instances>"
    exit(0)

units = argv[1]
runs = int(argv[2])
instances = argv[3:]

for instance in instances:
    infile = os.path.basename(instance)
    bestLeastColors = 10000
    bestInitialColors = 10000
    bestColors = empty(0)
    bestpermut = ""
    bestRunningTime = empty(0)
    for permutation in permute(units):
        leastColors = 10000
        initialColors = 10000
        colors = empty(0)
        runningTime = empty(0)
        for i in range(0, runs):
            jd = open("output/" + str(i) + "/" + infile + "." + permutation + ".json")
            data = json.load(jd)
            jd.close()
            colors = append(colors, data["colors"])
            initial = data["colors"] + data["improvement"]
            runningTime = append(runningTime, sum(time["all"]["time"]["sum"] for time in data["stats"]))

            if data["colors"] < leastColors:
                leastColors = data["colors"]
            if initial < initialColors: