x = random.randrange(r)
            yL = random.randrange(c // 2)
            y1 = random.randrange(c - yL + 1)
            for y in range(y1, y1 + yL):
                grid[x][y] = '.'
        else:  # horizontal path
            y = random.randrange(c)
            xL = random.randrange(r // 2)
            x1 = random.randrange(r - xL + 1)
            for x in range(x1, x1 + xL):
                grid[x][y] = '.'

    return grid


dn = 0
up = r + c

while dn + 1 < up:
    mid = (dn + up) // 2
    if helpers.solve(getGrid(mid), k) == -1:
        dn = mid
    else:
        up = mid

grid = getGrid(up)

print(r, c, k)
for row in grid:
    print(''.join(row))
示例#2
0
	start = position_repr(x_s,y_s) # doesn't matter
	
	santa_houses[start] = 1
	robo_santa_houses[start] = 1

	for char in input_string:
		
		if turn % 2 == 0: # santas turn
			x_s,y_s = move(x_s,y_s,char)
			santa_new_pos = position_repr(x_s,y_s)
			if santa_houses.has_key(santa_new_pos):
				santa_houses[santa_new_pos] += 1
			else:
				santa_houses[santa_new_pos] = 1
		else: # robo_santas turn
			x_r,y_r = move(x_r,y_r,char)
			rsanta_new_pos = position_repr(x_r,y_r)
			if robo_santa_houses.has_key(rsanta_new_pos):
				robo_santa_houses[rsanta_new_pos] += 1
			else:
				robo_santa_houses[rsanta_new_pos] = 1

		turn += 1

	from_santa = dict(santa_houses)
	from_santa.update(robo_santa_houses)

	return len(from_santa)

helpers.solve(DAY,PART,solution)
示例#3
0
import sys
from helpers import solve

if len(sys.argv) < 2:
    print("Please give file name as argument")
    quit()

filename = sys.argv[1]

with open(filename, "r", encoding="UTF-8") as file:
    input_lines = file.readlines()

solve(input_lines)
示例#4
0
文件: day2_pt1.py 项目: ssherko/aoc
	length = dimensions[0]
	width = dimensions[1]
	height = dimensions[2]

	length = int(float(length))
	width = int(float(width))
	height = int(float(height))

	return length,width,height

def get_surface_area(length,width,height):
	top = width * length
	front = length * height
	side = height * width

	slack = min([top,front,side])

	total_area = (top+front+side) * 2
	
	return (total_area + slack)

def solution(file_obj):
	total = 0
	for line in file_obj:
		l,w,h = get_params(line)
		total += get_surface_area(l,w,h)

	return total

helpers.solve(DAY,PART,solution,line_by_line=True)
示例#5
0
        lhs = evaluate(circuit, lval, store, verb)
        rhs = evaluate(circuit, rval, store, verb)
        result = lhs >> rhs
        store.append((result, command))
        return result


def check_store(store, command):
    for elem in store:
        val = elem[0]
        mem = elem[1]
        # the comparison might be a bit more clever (i.e.: a AND b == b AND a) ... too lazy.
        if cmp(command, mem) == 0:
            return val
    return None


def solution(f_obj):
    expression = {}
    store = []

    for line in f_obj:
        command = parse_line(line)
        key = command.pop("out")
        expression[key] = command

    return evaluate(expression, "a", store, verb=False)


helpers.solve(DAY, PART, solution, line_by_line=True)
示例#6
0
from helpers import solve

result_18 = solve(18)
result_42 = solve(42)

print("Part 1:")
print("Result for serial number 18:", result_18[0])
print("Result for serial number 42:", result_42[0])
print("\nPart 2:")
print("Result for serial number 18:", result_18[1])
print("Result for serial number 42:", result_42[1])
示例#7
0
from helpers import solve

result = solve(4842)

print("Solution for part 1:")
print(result[0])
print("\nSolution for part 2:")
print(result[1])