コード例 #1
0
def main():
	if len(sys.argv) == 1:
		print('Usage:', sys.argv[0], '<1|2> < input', file=sys.stderr)
		sys.exit(1)
	mode = sys.argv[1]
	valid_passphrases = (passphrase for passphrase in input_iter() if not has_duplicates(passphrase))
	if mode == '1':
		print(len(list(valid_passphrases)))
	elif mode == '2':
		print(sum(not has_anagram(p) for p in valid_passphrases))
コード例 #2
0
def answer(predicate):
    return sum(predicate(s) for s in input_iter())
コード例 #3
0
def main():
	if len(sys.argv) == 1:
		print('Usage:', sys.argv[0], '<1|2> < input', file=sys.stderr)
		sys.exit(1)
	print(answer(input_iter(), sys.argv[1] == '2'))
コード例 #4
0
#!/usr/bin/env python3
# encoding: utf-8

from ben import input_iter
import networkx as nx

# Create a graph of programs
graph = nx.Graph()

for line in input_iter():
    # Parse the line
    node, neighbors = line.split(' <-> ')

    # Add edges defined by this line
    graph.add_edges_from(
        (node, neighbor) for neighbor in neighbors.split(', '))

print('Part 1:', len(nx.node_connected_component(graph, '0')))
print('Part 2:', nx.number_connected_components(graph))