コード例 #1
0
ファイル: run.py プロジェクト: simonrozsival/advent-of-code
import sys

if len(sys.argv) < 2:
	print("Missing eggnog amount as an argument of the command")
	sys.exit(1)

from task import getCombinationsCount, getMinimalCombinationsCount
##

eggnog = int(sys.argv[1])

bottles = []
with open("in.txt") as file:
	for line in file:
		bottles.append(int(line))

# part 1

print("part 1:")
print("Combinations count: {}".format(getCombinationsCount(eggnog, bottles)))


# part 2

print("part 2:")
print("Combinations count with minimal bottles usage: {}".format(getMinimalCombinationsCount(eggnog, bottles)))
	
sys.exit(0)
コード例 #2
0
ファイル: test.py プロジェクト: simonrozsival/advent-of-code
from task import getCombinationsCount, getMinimalCombinationsCount

## write tests here --

# part 1

t.test("nothing to divide", getCombinationsCount(0, [1, 2, 3]), 1)
t.test("too small bottle", getCombinationsCount(10, [5]), 0)
t.test("one large enough bottle", getCombinationsCount(10, [10]), 1)
t.test("two bottles", getCombinationsCount(2, [2, 2]), 2)
t.test("two bottles, one too small", getCombinationsCount(2, [2, 1]), 1)
t.test("two small bottles", getCombinationsCount(2, [1, 1]), 1)

# part 2

t.test("", getMinimalCombinationsCount(10, [5, 5, 5, 10]), 1)

## -- end of tests

def askYesNo(question):
	print(question + " [y/n]")
	yes = set(['yes','y', 'ye', ''])
	no = set(['no','n'])	
	while True:
		choice = raw_input().lower()
		if choice in yes:
			return True
		elif choice in no:
			return False
		else:
			print("Answer with 'y' (yes) or 'n' (no).")