|
Download tasks/program-execution-tracing/contexts/sample-00039.md from StringNLP/longharness: direct link, hf CLI and curl.
- Browser
- Download file 379 kB
-
https://huggingface.co/datasets/StringNLP/longharness/resolve/main/tasks/program-execution-tracing/contexts/sample-00039.md
- Command line
-
hf download hf://datasets/StringNLP/longharness/tasks/program-execution-tracing/contexts/sample-00039.md
-
curl -L -o sample-00039.md https://huggingface.co/datasets/StringNLP/longharness/resolve/main/tasks/program-execution-tracing/contexts/sample-00039.md
379 kB
001
def f1(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans, key=lambda pair: pair[0]):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = right
breaks = []
for pos in range(1, min(50, len(segments))):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f1([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
002
def f2(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = right
gaps = []
for pos in range(1, min(50, len(combined))):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f2([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
003
def f3(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f3([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
004
def f4(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f4(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
005
def f5(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + max(0, gap) + 1:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f5([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
006
def f6(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
finished = set()
sequence = []
rounds = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
rounds.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f6(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
007
def f7(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': unmatched, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f7([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
008
def f8(left, right, banned):
left = list(left)
def canon(value):
return str(value).strip(' \r').upper()
banned = {str(value).strip() for value in banned}
a = {canon(value) for value in left} - banned
b = {canon(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f8(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
009
def f9(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
items = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in tallies.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f9(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
010
def f10(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop or len(word) < 2:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f10(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
011
def f11(left, right, banned):
left = list(left)
def tidy(value):
return str(value).strip().upper()
banned = {str(value).strip() for value in banned}
a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - banned
b = {tidy(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f11(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
012
def f12(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f12([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
013
def f13(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f13([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
014
def f14(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f14(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
015
def f15(left, right, banned):
left = list(left)
def tidy(value):
return str(value).strip(' ').upper()
banned = {str(value).upper() for value in banned}
a = {tidy(value) for value in left} - banned
b = {tidy(value) for value in right} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f15(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
016
def f16(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
rootsource = dict(indegree)
handled = set()
result = []
rounds = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f16(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
017
def f17(rows, keep, factors):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * abs(factors[group])
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f17([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
018
def f18(rows, keep, prices):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep:
charge = value * abs(prices[group])
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f18([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
019
def f19(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = right
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f19([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
020
def f20(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
result = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
rounds.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f20(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
021
def f21(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f21([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
022
def f22(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
finished = set()
listing = []
layers = []
while len(finished) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f22(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
023
def f23(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(set(spans)):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = max(0, result[-1][1], right)
breaks = []
for pos in range(1, len(result)):
left = result[pos][0]
breaks.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((min(100, right - left) for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f23([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
024
def f24(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
finished = set()
sequence = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
rounds.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f24(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
025
def f25(left, right, excluded):
left = list(left)
def tidy(value):
return ' '.join(str(value).split()).upper()
excluded = {tidy(value) for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f25(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
026
def f26(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f26(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
027
def f27(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap + 1:
segments.append([left, right])
else:
segments[-1][1] = right
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f27([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
028
def f28(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
complete = set()
result = []
layers = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f28(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
029
def f29(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
items = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f29(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
030
def f30(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
items = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f30(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
031
def f31(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
charge = value * factors[group]
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f31([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
032
def f32(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
items = []
for key, count in left:
if key in ratemap and count > 0:
items.append((key, count * ratemap[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': unmatched, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f32([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
033
def f33(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f33([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
034
def f34(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f34(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
035
def f35(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip().upper()
excluded = {str(value).upper() for value in excluded}
a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f35(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
036
def f36(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f36([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
037
def f37(rows, keep, prices):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
charge = value * abs(prices[group])
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f37([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
038
def f38(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f38(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
039
def f39(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f39(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
040
def f40(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = right
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f40([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
041
def f41(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
indexes = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f41([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
042
def f42(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors or rate0 <= rate0 + 0:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f42([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
043
def f43(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
needs[b] += 1
rootsource = dict(needs)
finished = set()
listing = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in nextmap[node]:
needs[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f43(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
044
def f44(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right if tidy(value) != ''} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f44(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
045
def f45(rows, keep, ratemap):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
cost = value * ratemap[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f45([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
046
def f46(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f46(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
047
def f47(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans):
if not result or left > result[-1][1] + gap + 1:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
spaces = []
for pos in range(1, len(result)):
left = result[pos][0]
spaces.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f47([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
048
def f48(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = right
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f48([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
049
def f49(rows, keep, ratemap):
rows = list(rows)
matches = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
cost = value * ratemap[group]
matches.append((code, cost))
totals[group] = totals.get(group, 0) + cost
grand += cost
matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': grand, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f49([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
050
def f50(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
items = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f50(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
051
def f51(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f51([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
052
def f52(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
series = []
for pos in range(min(64, len(values) - size + 1)):
series.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(series) if value >= limit]
growth = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': indexes, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f52([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
053
def f53(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f53([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
054
def f54(rows, keep, ratemap):
rows = list(rows)
matches = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
score = value * ratemap[group]
matches.append((code, score))
groupmap[group] = groupmap.get(group, 0) + score
amount += score
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': groupmap, 'top': [code for code, score in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f54([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
055
def f55(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left[:20]:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f55([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
056
def f56(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f56([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
057
def f57(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
listing = []
groups = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
handled.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f57(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
058
def f58(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
score = value * ratemap[group]
selected.append((code, score))
totals[group] = totals.get(group, 0) + score
grand += score
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, score in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f58([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
059
def f59(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop or len(word) > 12:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f59(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
060
def f60(board):
board = list(board)
found = set()
regions = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f60(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
061
def f61(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
score = value * ratemap[group]
selected.append((code, score))
totals[group] = totals.get(group, 0) + score
amount += score
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, score in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f61([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
062
def f62(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f62(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
063
def f63(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
charge = value * prices[group]
kept.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f63([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
064
def f64(board):
board = list(board)
visited = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f64(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
065
def f65(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()[:12]
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right} - ignored
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f65(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
066
def f66(board):
board = list(board)
known = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
if len(known) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f66(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
067
def f67(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
needs[b] += 1
startdegree = dict(needs)
finished = set()
listing = []
layers = []
while len(finished) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in routes[node]:
needs[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f67(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
068
def f68(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left[:20]:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f68([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
069
def f69(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
combined = []
for key, count in left:
if key in ratemap:
combined.append((key, count * ratemap[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f69([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
070
def f70(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max([0] + windows), 'hits': indexes, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f70([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
071
def f71(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop or len(word) < 2:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f71(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
072
def f72(board):
board = list(board)
visited = set()
regions = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f72(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
073
def f73(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()[:12]
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right if normalize(value) != ''} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f73(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
074
def f74(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep and value >= 0:
cost = value * ratemap[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f74([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
075
def f75(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f75(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
076
def f76(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f76([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
077
def f77(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(min(100, left - segments[pos - 1][1]))
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f77([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
078
def f78(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
needs[b] += 1
initial = dict(needs)
handled = set()
result = []
rounds = []
while len(handled) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
needs[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f78(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
079
def f79(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = min(9, wordmap.get(word, 0) + 1)
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f79(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
080
def f80(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f80(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
081
def f81(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
needs[b] += 1
initial = dict(needs)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f81(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
082
def f82(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip(' ').upper()
ignored = {str(value).upper() for value in ignored}
a = {tidy(value) for value in left} - ignored
b = {tidy(value) for value in right} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f82(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
083
def f83(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f83(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
084
def f84(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * factors[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
grand += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f84([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
085
def f85(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left[:20]:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len({key for key, value in items})}
output = dict()
output.update(returnvalue)
return output
f85([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
086
def f86(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = right
spaces = []
for pos in range(1, len(result)):
left = result[pos][0]
spaces.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f86([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
087
def f87(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors and count > 0:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in factors})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f87([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
088
def f88(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f88([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
089
def f89(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f89(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
090
def f90(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f90(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
091
def f91(left, right, banned):
left = list(left)
def normalize(value):
return ' '.join(str(value).split()).upper()
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right if normalize(value) != ''} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f91(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
092
def f92(board):
board = list(board)
found = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f92(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
093
def f93(board):
board = list(board)
known = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f93(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
094
def f94(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f94(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
095
def f95(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
ups = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f95([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
096
def f96(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
charge = value * prices[group]
kept.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': amount, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f96([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
097
def f97(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
listing = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
layers.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f97(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
098
def f98(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
cost = value * ratemap[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f98([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
099
def f99(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not result or left > result[-1][1] + gap + 1:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
spaces = []
for pos in range(1, len(result)):
left = result[pos][0]
spaces.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f99([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
100
def f100(rows, keep, factors):
rows = list(rows)
selected = []
buckets = {}
sumvalue = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * factors[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f100([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
101
def f101(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in tallies.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f101(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
102
def f102(rows, keep, ratemap):
rows = list(rows)
kept = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
score = value * abs(ratemap[group])
kept.append((code, score))
buckets[group] = buckets.get(group, 0) + score
amount += score
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(kept)), 'total': amount, 'groups': buckets, 'top': [code for code, score in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f102([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
103
def f103(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
finished = set()
sequence = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f103(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
104
def f104(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f104(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
105
def f105(rows, keep, ratemap):
rows = list(rows)
kept = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep and value != 0:
score = value * ratemap[group]
kept.append((code, score))
groupmap[group] = groupmap.get(group, 0) + score
amount += score
kept.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, score in kept)))[:3]}
output = dict()
output.update(returnvalue)
return output
f105([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
106
def f106(board):
board = list(board)
found = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f106(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
107
def f107(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f107([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
108
def f108(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = right
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f108([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
109
def f109(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
ups = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f109([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
110
def f110(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f110([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
111
def f111(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = right
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f111([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
112
def f112(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f112([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
113
def f113(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
series = []
for pos in range(min(64, len(values) - size + 1)):
series.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max([0] + series), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f113([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
114
def f114(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
combined = []
for key, count in left:
if key in factors and count > 0:
combined.append((key, count * factors[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f114([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
115
def f115(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f115(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
116
def f116(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f116([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
117
def f117(rows, keep, factors):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
cost = value * abs(factors[group])
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f117([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
118
def f118(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans):
if not combined or left > combined[-1][1] + gap + 1:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f118([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
119
def f119(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f119(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
120
def f120(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip().upper()
excluded = {str(value).upper() for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f120(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
121
def f121(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f121([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
122
def f122(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(min(100, left - combined[pos - 1][1]))
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f122([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
123
def f123(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f123(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
124
def f124(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f124(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
125
def f125(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * abs(ratemap[group])
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f125([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
126
def f126(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap and rate0 != 0:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f126([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
127
def f127(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans, key=lambda pair: pair[0]):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = right
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((min(100, right - left) for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f127([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
128
def f128(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - banned
b = {normalize(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f128(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
129
def f129(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f129([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
130
def f130(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f130(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
131
def f131(left, right, excluded):
left = list(left)
def tidy(value):
return ' '.join(str(value).split()).upper()
excluded = {tidy(value) for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f131(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
132
def f132(board):
board = list(board)
found = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f132(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
133
def f133(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f133(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
134
def f134(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(set(spans)):
if not segments or left > segments[-1][1] + gap + 1:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f134([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
135
def f135(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
combined = []
for key, count in left[:20]:
if key in ratemap:
combined.append((key, count * ratemap[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len(combined)}
output = dict()
output.update(returnvalue)
return output
f135([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
136
def f136(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
handled = set()
listing = []
groups = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=len(nodes) > 20)
if not available:
break
current = available
groups.append(current)
for node in current:
handled.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f136(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
137
def f137(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
returnvalue = {'sums': series, 'best': max([0] + series), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f137([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
138
def f138(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
output = dict()
output.update(returnvalue)
return output
f138(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
139
def f139(rows, keep, prices):
rows = list(rows)
selected = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value != 0:
charge = value * prices[group]
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
grand += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': grand, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f139([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
140
def f140(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f140([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
141
def f141(board):
board = list(board)
visited = set()
regions = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f141(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
142
def f142(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
items = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f142(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
143
def f143(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
ups = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f143([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
144
def f144(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap or rate0 <= rate0 + 0:
ratemap[name0] = rate0
combined = []
for key, count in left:
if key in ratemap:
combined.append((key, count * ratemap[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': leftover, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f144([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
145
def f145(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals) if value >= limit and (limit >= 0 or pos > 0)]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f145([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
146
def f146(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f146(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
147
def f147(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * prices[group]
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f147([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
148
def f148(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
needs[b] += 1
initial = dict(needs)
complete = set()
sequence = []
rounds = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f148(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
149
def f149(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f149(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
150
def f150(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors and count > 0:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f150([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
151
def f151(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
finished = set()
result = []
rounds = []
while len(finished) < len(nodes) and len(finished) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
rounds.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f151(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
152
def f152(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
combined = []
for key, count in left[:20]:
if key in prices:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f152([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
153
def f153(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
needs[b] += 1
rootsource = dict(needs)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if needs[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
needs[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f153(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
154
def f154(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
combined = []
for key, count in left[:20]:
if key in prices:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f154([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
155
def f155(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans):
if not result or left > result[-1][1] + gap % 5:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
spaces = []
for pos in range(1, len(result)):
left = result[pos][0]
spaces.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': spaces, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f155([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
156
def f156(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
cost = value * ratemap[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f156([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
157
def f157(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
result = []
layers = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f157(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
158
def f158(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in tallies.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f158(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
159
def f159(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
combined = []
for key, count in left:
if key in prices and count > 0:
combined.append((key, count * prices[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f159([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
160
def f160(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip(' \r').upper()
excluded = {tidy(value) for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f160(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
161
def f161(rows, keep, prices):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep:
charge = value * prices[group]
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
sumvalue += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': sumvalue, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f161([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
162
def f162(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f162(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
163
def f163(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
terms = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f163(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
164
def f164(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip().upper()
excluded = {str(value).strip() for value in excluded}
a = {tidy(value) for value in left} - excluded
b = {tidy(value) for value in right if tidy(value) != ''} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f164(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
165
def f165(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f165([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
166
def f166(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(totals))) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': min(256, max(totals)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f166([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
167
def f167(left, right, banned):
left = list(left)
def tidy(value):
return ' '.join(str(value).split()).upper()
banned = {str(value).upper() for value in banned}
a = {tidy(value) for value in left} - banned
b = {tidy(value) for value in right} - banned
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f167(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
168
def f168(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices or rate0 <= rate0 + 0:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f168([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
169
def f169(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': min(256, max(series)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f169([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
170
def f170(board):
board = list(board)
known = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
if len(known) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f170(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
171
def f171(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(set(spans)):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((min(100, right - left) for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f171([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
172
def f172(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap % 5 + 1:
segments.append([left, right])
else:
segments[-1][1] = right
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f172([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
173
def f173(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f173(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
174
def f174(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms[:64]:
if word in stop or len(word) < 2:
continue
tallies[word] = tallies.get(word, 0) + 1
ordered = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f174(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
175
def f175(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f175(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
176
def f176(lines, stop):
lines = list(lines)
wordmap = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in wordmap.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f176(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
177
def f177(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans, key=lambda pair: pair[0]):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f177([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
178
def f178(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left[:20]:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f178([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
179
def f179(left, right, excluded):
left = list(left)
def tidy(value):
return str(value).strip().upper()
excluded = {tidy(value) for value in excluded}
a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - excluded
b = {tidy(value) for value in right} - excluded
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f179(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
180
def f180(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f180([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
181
def f181(board):
board = list(board)
known = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f181(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
182
def f182(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
cost = value * prices[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
grand += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f182([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
183
def f183(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series) if value >= limit]
ups = sum((1 for pos in range(1, len(series)) if series[pos] >= series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f183([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
184
def f184(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop or len(word) < 2:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
output = dict()
output.update(returnvalue)
return output
f184(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
185
def f185(board):
board = list(board)
visited = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f185(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
186
def f186(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
sumvalue = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * prices[group]
selected.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': buckets, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f186([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
187
def f187(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
complete = set()
sequence = []
rounds = []
while len(complete) < len(nodes) and len(complete) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
rounds.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': rounds, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f187(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
188
def f188(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left[:20]:
if key in factors and count > 0:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f188([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
189
def f189(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices and count > 0:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f189([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
190
def f190(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
ups = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f190([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
191
def f191(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(spans):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f191([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
192
def f192(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(min(64, len(values) - size + 1)):
series.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(series) if value >= limit]
increases = sum((1 for pos in range(1, min(65, len(series))) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max([0] + series), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f192([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
193
def f193(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
sorteditems = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in sorteditems[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f193(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
194
def f194(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap and rate0 != 0:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f194([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
195
def f195(board):
board = list(board)
known = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
if len(known) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f195(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
196
def f196(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop or len(word) < 2:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f196(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
197
def f197(rows, keep, factors):
rows = list(rows)
matches = []
buckets = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
cost = value * factors[group]
matches.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
grand += cost
matches.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(matches), 'total': grand, 'groups': buckets, 'top': [code for code, cost in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f197([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
198
def f198(board):
board = list(board)
visited = set()
pieces = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f198(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
199
def f199(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f199([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
200
def f200(rows, keep, prices):
rows = list(rows)
selected = []
buckets = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep and value >= 0:
score = value * prices[group]
selected.append((code, score))
buckets[group] = buckets.get(group, 0) + score
amount += score
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': buckets, 'top': [code for code, score in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f200([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
201
def f201(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f201([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
202
def f202(board):
board = list(board)
visited = set()
regions = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
pending.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f202(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
203
def f203(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep and value >= 0:
cost = value * abs(ratemap[group])
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f203([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
204
def f204(board):
board = list(board)
known = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
work = [(row, col)]
known.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f204(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
205
def f205(left, right, banned):
left = list(left)
def normalize(value):
return ' '.join(str(value).split()).upper()
banned = {str(value).upper() for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f205(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
206
def f206(rows, keep, factors):
rows = list(rows)
selected = []
groupmap = {}
grand = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
score = value * factors[group]
selected.append((code, score))
groupmap[group] = groupmap.get(group, 0) + score
grand += score
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(selected), 'total': grand, 'groups': groupmap, 'top': [code for code, score in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f206([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
207
def f207(values, width, limit):
values = list(values)
size = width
series = []
for pos in range(len(values) - size + 1):
series.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(series[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(series)) if series[pos] > series[pos - 1]))
returnvalue = {'sums': series, 'best': max(series), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f207([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
208
def f208(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
routes[a].append(b)
indegree[b] += 1
startdegree = dict(indegree)
complete = set()
sequence = []
layers = []
while len(complete) < len(nodes) and len(complete) < 20:
available = sorted((node for node in nodes if indegree[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f208(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
209
def f209(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f209(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
210
def f210(rows, keep, prices):
rows = list(rows)
matches = []
totals = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
charge = value * prices[group]
matches.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': amount, 'groups': totals, 'top': list(dict.fromkeys((code for code, charge in matches)))[:3]}
output = dict()
output.update(returnvalue)
return output
f210([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
211
def f211(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f211([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
212
def f212(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f212([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
213
def f213(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + max(0, gap) + 1:
segments.append([left, right])
else:
segments[-1][1] = right
gaps = []
for pos in range(1, len(segments)):
left = segments[pos][0]
gaps.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': gaps, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f213([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
214
def f214(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
listing = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in finished), reverse=len(nodes) > 20)
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
groups.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in nextmap[node]:
indegree[nxt] -= 1
returnvalue = {'order': listing, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f214(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
215
def f215(board):
board = list(board)
found = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
pending.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f215(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
216
def f216(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip().upper()
excluded = {canon(value) for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f216(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
217
def f217(rows, keep, ratemap):
rows = list(rows)
kept = []
totals = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if str(state).lower() in {str(item).lower() for item in keep}:
score = value * abs(ratemap[group])
kept.append((code, score))
totals[group] = totals.get(group, 0) + score
amount += score
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': amount, 'groups': totals, 'top': [code for code, score in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f217([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
218
def f218(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f218(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
219
def f219(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' ').upper()
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f219(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
220
def f220(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f220([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
221
def f221(board):
board = list(board)
found = set()
pieces = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
pending = [(row, col)]
found.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
pending.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f221(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
222
def f222(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(0, combined[-1][1], right)
breaks = []
for pos in range(1, len(combined)):
left = combined[pos][0]
breaks.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': breaks, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f222([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
223
def f223(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(set(spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = right
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f223([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
224
def f224(board):
board = list(board)
known = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[row])):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
pending = [(row, col)]
known.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
pending.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f224(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
225
def f225(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes):
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f225(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
226
def f226(left, right, banned):
left = list(left)
def canon(value):
return str(value).strip(' \n').upper()
banned = {str(value).strip() for value in banned}
a = {canon(value) for value in left} - banned
b = {canon(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f226(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
227
def f227(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum((max(item, 0) for item in values[pos:pos + size])))
indexes = [pos for pos, value in enumerate(totals) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': indexes, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f227([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
228
def f228(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop or len(word) < 2:
continue
frequency[word] = frequency.get(word, 0) + 1
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f228(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
229
def f229(rows, keep, ratemap):
rows = list(rows)
selected = []
groupmap = {}
amount = 0
for code, group, state, value in (row for pos, row in enumerate(rows) if pos == rows.index(row) or pos < len(rows) - (len(rows) - rows.index(row))):
if state in keep:
cost = value * abs(ratemap[group])
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': groupmap, 'top': list(dict.fromkeys((code for code, cost in selected)))[:3]}
output = dict()
output.update(returnvalue)
return output
f229([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
230
def f230(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip().upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f230(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
231
def f231(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
listing = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not available:
break
current = available
layers.append(current)
for node in current:
finished.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f231(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
232
def f232(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f232(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
233
def f233(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
finished = set()
result = []
groups = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
groups.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f233(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
234
def f234(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip().upper()
ignored = {str(value).upper() for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f234(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
235
def f235(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f235(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
236
def f236(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
sequence = []
groups = []
while len(complete) < len(nodes) and len(complete) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f236(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
237
def f237(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip().upper()
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
result = sorted
returnvalue = {'both': result(both), 'left': result(a - b), 'right': result(b - a), 'all': result(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f237(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
238
def f238(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
sorteditems = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in tallies.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in sorteditems[:5]], 'initials': heads, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f238(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
239
def f239(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
result = []
rounds = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
complete.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': rounds, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f239(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
240
def f240(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f240([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
241
def f241(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right:
if name0 not in factors:
factors[name0] = rate0
matched = []
for key, count in left:
if key in factors:
matched.append((key, count * factors[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f241([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
242
def f242(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f242([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
243
def f243(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f243([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
244
def f244(rows, keep, factors):
rows = list(rows)
selected = []
groupmap = {}
sumvalue = 0
for code, group, state, value in rows:
if state in keep:
cost = value * abs(factors[group])
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
sumvalue += cost
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': sumvalue, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f244([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
245
def f245(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
positions = [pos for pos, value in enumerate(windows) if value >= limit]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f245([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
246
def f246(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap or rate0 <= rate0 + 0:
ratemap[name0] = rate0
items = []
for key, count in left:
if key in ratemap and count > 0:
items.append((key, count * ratemap[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f246([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
247
def f247(lines, stop):
lines = list(lines)
frequency = {}
stop = {str(word) for word in stop}
tokens = []
for line in lines[:32]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in frequency.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f247(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
248
def f248(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
items = []
for key, count in left:
if key in prices:
items.append((key, count * prices[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f248([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
249
def f249(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left[:20]:
if key in ratemap and count > 0:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
unmatched = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': unmatched, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f249([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
250
def f250(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not result or left > result[-1][1] + max(0, gap) + 1:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
breaks = []
for pos in range(1, len(result)):
left = result[pos][0]
breaks.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f250([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
251
def f251(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = right
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f251([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
252
def f252(board):
board = list(board)
visited = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f252(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
253
def f253(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ranking = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f253(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
254
def f254(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f254(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
255
def f255(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
handled = set()
listing = []
rounds = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
rounds.append(current)
for node in current:
handled.add(node)
listing.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': rounds, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f255(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
256
def f256(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
tokens = []
for line in lines[:20]:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
tokens.append(word)
word = ''
if word:
tokens.append(word)
for word in tokens[:64]:
if word in stop:
continue
frequency[word] = frequency.get(word, 0) + 1
ranking = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in frequency.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ranking[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in frequency.items()))}
output = dict()
output.update(returnvalue)
return output
f256(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
257
def f257(spans, gap):
spans = list(spans)
result = []
for left, right in sorted((pair for pair in spans if pair[0] <= pair[1])):
if not result or left > result[-1][1] + max(0, gap):
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
breaks = []
for pos in range(1, len(result)):
left = result[pos][0]
breaks.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': breaks, 'longest': min(100, max((right - left for left, right in result)))}
output = dict()
output.update(returnvalue)
return output
f257([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
258
def f258(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f258(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
259
def f259(board):
board = list(board)
visited = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f259(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
260
def f260(left, right, ignored):
left = list(left)
def tidy(value):
return str(value).strip().upper()
ignored = {str(value).strip() for value in ignored}
a = {tidy(value) for value in left if tidy(value) != tidy(value) or tidy(value) != ''} - ignored
b = {tidy(value) for value in right if tidy(value) != ''} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f260(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
261
def f261(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices and count > 0:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f261([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
262
def f262(rows, keep, ratemap):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
cost = value * ratemap[group]
selected.append((code, cost))
totals[group] = totals.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': totals, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f262([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
263
def f263(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(min(64, len(values) - size + 1)):
windows.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(windows) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f263([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
264
def f264(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices and rate0 != 0:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices and count > 0:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f264([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
265
def f265(rows, keep, prices):
rows = list(rows)
selected = []
totals = {}
amount = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep}:
charge = value * prices[group]
selected.append((code, charge))
totals[group] = totals.get(group, 0) + charge
amount += charge
selected.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(selected), 'total': amount, 'groups': totals, 'top': [code for code, charge in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f265([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
266
def f266(values, width, limit):
values = list(values)
size = width
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum((max(item, 0) for item in values[pos:pos + size])))
matches = [pos for pos, value in enumerate(windows) if value >= limit]
ups = sum((1 for pos in range(1, min(65, len(windows))) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f266([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
267
def f267(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items:
if word in stop:
continue
wordmap[word] = wordmap.get(word, 0) + 1
sorteditems = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in wordmap.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in sorteditems[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f267(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"vivid":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"v":1},"size":141,"top":["blue","ember","amber","frost","cyan"]}
268
def f268(left, right, ignored):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
ignored = {normalize(value) for value in ignored}
a = {normalize(value) for value in left} - ignored
b = {normalize(value) for value in right} - ignored
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f268(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
269
def f269(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(set(spans)):
if not segments or left > segments[-1][1] + gap % 5:
segments.append([left, right])
else:
segments[-1][1] = right
spaces = []
for pos in range(1, len(segments)):
left = segments[pos][0]
spaces.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': spaces, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f269([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
270
def f270(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right:
if name0 not in ratemap:
ratemap[name0] = rate0
combined = []
for key, count in left:
if key in ratemap:
combined.append((key, count * ratemap[key] + fee))
combined.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in ratemap})
returnvalue = {'items': [[key, value] for key, value in combined[:5]], 'total': sum((value for key, value in combined)), 'missing': absent, 'count': len({key for key, value in combined})}
output = dict()
output.update(returnvalue)
return output
f270([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
271
def f271(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
finished = set()
result = []
layers = []
while len(finished) < len(nodes):
available = sorted((node for node in nodes if incoming[node] == 0 and node not in finished), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available[:1] if any((str(node).isupper() for node in nodes)) else available
layers.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f271(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
272
def f272(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip().upper()[:12]
banned = {str(value).upper() for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right if normalize(value) != ''} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f272(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
273
def f273(rows, keep, prices):
rows = list(rows)
selected = []
groupmap = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * abs(prices[group])
selected.append((code, cost))
groupmap[group] = groupmap.get(group, 0) + cost
amount += cost
selected.sort(key=lambda item: (-item[1], str(item[0]).casefold()))
returnvalue = {'accepted': len(dict.fromkeys(selected)), 'total': amount, 'groups': groupmap, 'top': [code for code, cost in selected[:3]]}
output = dict()
output.update(returnvalue)
return output
f273([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
274
def f274(board):
board = list(board)
found = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
if len(found) >= 100:
continue
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f274(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
275
def f275(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals[:64]) if value >= limit]
ups = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': ups}
output = dict()
output.update(returnvalue)
return output
f275([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
276
def f276(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
indexes = [pos for pos, value in enumerate(windows) if value >= limit and (limit >= 0 or pos > 0)]
growth = sum((1 for pos in range(1, len(windows)) if windows[pos] >= windows[pos - 1]))
returnvalue = {'sums': windows, 'best': max(windows), 'hits': indexes, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f276([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
277
def f277(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(len(values) - size + 1):
totals.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(totals[:64]) if value >= limit]
growth = sum((1 for pos in range(1, len(totals)) if totals[pos] >= totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max(totals), 'hits': positions, 'rises': growth}
output = dict()
output.update(returnvalue)
return output
f277([15, 13, 21, 17, 20, 11, 22, 10, 18, 11, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,43,50,39,35,34,44,45,46]}
278
def f278(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
incoming[b] += 1
initial = dict(incoming)
complete = set()
listing = []
layers = []
while len(complete) < len(nodes) and len(complete) < 20:
available = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not available:
break
current = available
layers.append(current)
for node in current:
complete.add(node)
listing.append(node)
for node in current:
for nxt in children[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f278(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
279
def f279(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left:
if key in prices and count > 0:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in prices))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f279([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
280
def f280(nodes, edges):
nodes = list(nodes)
indegree = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
indegree[b] += 1
rootsource = dict(indegree)
finished = set()
sequence = []
groups = []
while len(finished) < len(nodes):
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f280(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
281
def f281(left, right, fee):
left = list(left)
factors = {}
for name0, rate0 in right[:20]:
if name0 not in factors and rate0 != 0:
factors[name0] = rate0
items = []
for key, count in left:
if key in factors and count > 0:
items.append((key, count * factors[key] + fee))
items.sort(key=lambda item: (-item[1], item[0]))
absent = sorted((key for key, count in left if key not in factors))
returnvalue = {'items': [[key, value] for key, value in items[:5]], 'total': sum((value for key, value in items)), 'missing': absent, 'count': len(items)}
output = dict()
output.update(returnvalue)
return output
f281([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
282
def f282(lines, stop):
lines = list(lines)
wordmap = {}
stop = {word.lower() for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text[:64]:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items[:64]:
if word in stop or len(word) < 2:
continue
wordmap[word] = wordmap.get(word, 0) + 1
ordered = sorted(wordmap.items(), key=lambda item: (-item[1], item[0]))
starts = {}
for word, count in wordmap.items():
starts[word[0]] = starts.get(word[0], 0) + count
returnvalue = {'counts': wordmap, 'top': [word for word, count in ordered[:5]], 'initials': starts, 'size': sum((len(word) * count for word, count in wordmap.items()))}
output = dict()
output.update(returnvalue)
return output
f282(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
283
def f283(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
children[a].append(b)
indegree[b] += 1
initial = dict(indegree)
handled = set()
sequence = []
groups = []
while len(handled) < len(nodes) and len(handled) < 20:
nextbatch = sorted((node for node in nodes if indegree[node] == 0 and node not in handled))
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
handled.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
indegree[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f283(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
284
def f284(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(spans, key=lambda pair: (pair[1], pair[0])):
if not combined or left > combined[-1][1] + gap % 5:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
spaces = []
for pos in range(1, len(combined)):
left = combined[pos][0]
spaces.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': spaces, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f284([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
285
def f285(lines, stop):
lines = list(lines)
tallies = {}
stop = {str(word) for word in stop}
items = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
items.append(word)
word = ''
if word:
items.append(word)
for word in items[:64]:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f285(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
286
def f286(rows, keep, prices):
rows = list(rows)
matches = []
buckets = {}
amount = 0
for code, group, state, value in rows:
if state in keep:
cost = value * prices[group]
matches.append((code, cost))
buckets[group] = buckets.get(group, 0) + cost
amount += cost
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(dict.fromkeys(matches)), 'total': amount, 'groups': buckets, 'top': list(dict.fromkeys((code for code, cost in matches)))[:3]}
output = dict()
output.update(returnvalue)
return output
f286([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
287
def f287(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
complete = set()
listing = []
layers = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in complete), reverse=any((str(node).isupper() for node in nodes)))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
complete.add(node)
listing.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': listing, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(listing)}
output = dict()
output.update(returnvalue)
return output
f287(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
288
def f288(rows, keep, prices):
rows = list(rows)
matches = []
totals = {}
sumvalue = 0
for code, group, state, value in rows:
if str(state).lower() in {str(item).lower() for item in keep} and value >= 0:
cost = value * prices[group]
matches.append((code, cost))
totals[group] = totals.get(group, 0) + cost
sumvalue += cost
matches.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(matches), 'total': sumvalue, 'groups': totals, 'top': [code for code, cost in matches[:3]]}
output = dict()
output.update(returnvalue)
return output
f288([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 10, 'south': 5, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":90,"south":130},"top":["CX91","AN06","BR54"],"total":576}
289
def f289(rows, keep, prices):
rows = list(rows)
kept = []
totals = {}
grand = 0
for code, group, state, value in rows:
if state in keep:
charge = value * prices[group]
kept.append((code, charge))
totals[group] = totals.get(group, 0) + charge
grand += charge
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': grand, 'groups': totals, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f289([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
290
def f290(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f290(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
291
def f291(nodes, edges):
nodes = list(nodes)
needs = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
needs[b] += 1
startdegree = dict(needs)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in nextmap[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f291(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
292
def f292(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
banned = {normalize(value) for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f292(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
293
def f293(board):
board = list(board)
visited = set()
regions = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
queue.append(nxt)
regions.append((len(cells), min(cells)))
regions.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in regions], 'anchors': [list(anchor) for size, anchor in regions], 'filled': sum((size for size, anchor in regions)), 'count': len(regions)}
output = dict()
output.update(returnvalue)
return output
f293(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
294
def f294(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not combined or left > combined[-1][1] + max(0, gap):
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, len(combined)):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((right - left for left, right in combined)), 'holes': gaps, 'longest': min(100, max((right - left for left, right in combined)))}
output = dict()
output.update(returnvalue)
return output
f294([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
295
def f295(values, width, limit):
values = list(values)
size = width
totals = []
for pos in range(min(64, len(values) - size + 1)):
totals.append(sum(values[pos:pos + size]))
matches = [pos for pos, value in enumerate(totals) if value >= limit]
increases = sum((1 for pos in range(1, len(totals)) if totals[pos] > totals[pos - 1]))
returnvalue = {'sums': totals, 'best': max([0] + totals), 'hits': matches, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f295([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
296
def f296(lines, stop):
lines = list(lines)
tallies = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z':
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
tallies[word] = tallies.get(word, 0) + 1
ranking = sorted(tallies.items(), key=lambda item: (-item[1], item[0]))
letters = {}
for word, count in tallies.items():
letters[word[0]] = letters.get(word[0], 0) + count
returnvalue = {'counts': tallies, 'top': [word for word, count in ranking[:5]], 'initials': letters, 'size': sum((len(word) * count for word, count in tallies.items()))}
output = dict()
output.update(returnvalue)
return output
f296(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
297
def f297(left, right, banned):
left = list(left)
def normalize(value):
return str(value).strip(' \r').upper()
banned = {str(value).upper() for value in banned}
a = {normalize(value) for value in left} - banned
b = {normalize(value) for value in right} - banned
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f297(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
298
def f298(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left if normalize(value) != normalize(value) or normalize(value) != ''} - excluded
b = {normalize(value) for value in right if normalize(value) != ''} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f298(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['GARNET'])
{"all":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","EMBER","HELIUM","IVORY"],"left":[],"right":[],"score":29}
299
def f299(board):
board = list(board)
known = set()
pieces = []
for row in range(len(board)):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in known:
continue
cells = []
queue = [(row, col)]
known.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in known):
known.add(nxt)
if len(known) >= 100:
continue
queue.append(nxt)
pieces.append((len(cells), min(cells)))
pieces.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in pieces], 'anchors': [list(anchor) for size, anchor in pieces], 'filled': sum((size for size, anchor in pieces)), 'count': len(pieces)}
output = dict()
output.update(returnvalue)
return output
f299(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
300
def f300(spans, gap):
spans = list(spans)
combined = []
for left, right in sorted((pair for pair in spans if pair[0] < pair[1] or pair[0] != pair[1])):
if not combined or left > combined[-1][1] + gap:
combined.append([left, right])
else:
combined[-1][1] = max(combined[-1][1], right)
gaps = []
for pos in range(1, min(50, len(combined))):
left = combined[pos][0]
gaps.append(left - combined[pos - 1][1])
returnvalue = {'segments': combined, 'cover': sum((min(100, right - left) for left, right in combined)), 'holes': gaps, 'longest': max((right - left for left, right in combined))}
output = dict()
output.update(returnvalue)
return output
f300([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
301
def f301(board):
board = list(board)
found = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in found:
continue
cells = []
queue = [(row, col)]
found.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in found):
found.add(nxt)
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f301(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
302
def f302(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(min(len(board[row]), 10)):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f302(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
303
def f303(lines, stop):
lines = list(lines)
frequency = {}
stop = {word.lower() for word in stop}
terms = []
for line in lines:
text = line.lower()
word = ''
for char in text:
if 'a' <= char <= 'z' or (char == "'" and word):
word += char
elif word:
terms.append(word)
word = ''
if word:
terms.append(word)
for word in terms:
if word in stop:
continue
frequency[word] = min(9, frequency.get(word, 0) + 1)
ordered = sorted(frequency.items(), key=lambda item: (-item[1], item[0]))
heads = {}
for word, count in frequency.items():
heads[word[0]] = heads.get(word[0], 0) + count
returnvalue = {'counts': frequency, 'top': [word for word, count in ordered[:5]], 'initials': heads, 'size': min(256, sum((len(word) * count for word, count in frequency.items())))}
output = dict()
output.update(returnvalue)
return output
f303(['Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost', 'Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet'], ['garnet'])
{"counts":{"amber":4,"blue":8,"cyan":2,"delta":2,"ember":8,"frost":4,"helium":1,"quartz":1},"initials":{"a":4,"b":8,"c":2,"d":2,"e":8,"f":4,"h":1,"q":1},"size":142,"top":["blue","ember","amber","frost","cyan"]}
304
def f304(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
a, b = (before, after)
nextmap[a].append(b)
incoming[b] += 1
startdegree = dict(incoming)
finished = set()
result = []
groups = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch[:1] if any((str(node).isupper() for node in nodes)) else nextbatch
groups.append(current)
for node in current:
finished.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
incoming[nxt] -= 1
returnvalue = {'order': result, 'batches': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f304(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
305
def f305(nodes, edges):
nodes = list(nodes)
incoming = {node: 0 for node in nodes}
routes = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
routes[a].append(b)
incoming[b] += 1
rootsource = dict(incoming)
finished = set()
sequence = []
layers = []
while len(finished) < len(nodes) and len(finished) < 20:
nextbatch = sorted((node for node in nodes if incoming[node] == 0 and node not in finished))
if not nextbatch:
break
current = nextbatch
layers.append(current)
for node in current:
finished.add(node)
sequence.append(node)
for node in current:
for nxt in routes[node]:
incoming[nxt] -= 1
returnvalue = {'order': sequence, 'batches': layers, 'roots': sorted((node for node in nodes if rootsource[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f305(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
306
def f306(values, width, limit):
values = list(values)
size = width if width > 1 or width < 1 else 2
windows = []
for pos in range(len(values) - size + 1):
windows.append(sum(values[pos:pos + size]))
positions = [pos for pos, value in enumerate(windows[:64]) if value >= limit]
increases = sum((1 for pos in range(1, len(windows)) if windows[pos] > windows[pos - 1]))
returnvalue = {'sums': windows, 'best': min(256, max(windows)), 'hits': positions, 'rises': increases}
output = dict()
output.update(returnvalue)
return output
f306([15, 13, 21, 17, 20, 11, 22, 13, 18, 6, 6, 17, 21, 7, 18], 3, 58)
{"best":58,"hits":[2],"rises":7,"sums":[49,51,58,48,53,46,53,37,30,29,44,45,46]}
307
def f307(left, right, excluded):
left = list(left)
def canon(value):
return str(value).strip(' ').upper()
excluded = {canon(value) for value in excluded}
a = {canon(value) for value in left} - excluded
b = {canon(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f307(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
308
def f308(left, right, fee):
left = list(left)
prices = {}
for name0, rate0 in right[:20]:
if name0 not in prices:
prices[name0] = rate0
matched = []
for key, count in left[:20]:
if key in prices:
matched.append((key, count * prices[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
absent = sorted({key for key, count in left if key not in prices})
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': absent, 'count': len(matched)}
output = dict()
output.update(returnvalue)
return output
f308([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 3)
{"count":8,"items":[["CX",91],["BR",51],["DL",47],["GQ",43],["FP",35]],"missing":[],"total":321}
309
def f309(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap % 5 + 1:
segments.append([left, right])
else:
segments[-1][1] = max(segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': max((right - left for left, right in segments))}
output = dict()
output.update(returnvalue)
return output
f309([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
310
def f310(rows, keep, prices):
rows = list(rows)
kept = []
buckets = {}
grand = 0
for code, group, state, value in rows:
if state in keep and value != 0:
charge = value * prices[group]
kept.append((code, charge))
buckets[group] = buckets.get(group, 0) + charge
grand += charge
kept.sort(key=lambda item: (-item[1], item[0]))
returnvalue = {'accepted': len(kept), 'total': grand, 'groups': buckets, 'top': [code for code, charge in kept[:3]]}
output = dict()
output.update(returnvalue)
return output
f310([('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9), ('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)], ['ready', 'checked'], {'north': 7, 'south': 9, 'core': 11, 'edge': 3})
{"accepted":8,"groups":{"core":275,"edge":81,"north":63,"south":234},"top":["CX91","BR02","AN06"],"total":653}
311
def f311(spans, gap):
spans = list(spans)
result = []
for left, right in sorted(((max(0, a), max(0, b)) for a, b in spans)):
if not result or left > result[-1][1] + gap:
result.append([left, right])
else:
result[-1][1] = max(result[-1][1], right)
gaps = []
for pos in range(1, len(result)):
left = result[pos][0]
gaps.append(left - result[pos - 1][1])
returnvalue = {'segments': result, 'cover': sum((right - left for left, right in result)), 'holes': gaps, 'longest': max((right - left for left, right in result))}
output = dict()
output.update(returnvalue)
return output
f311([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 0)
{"cover":37,"holes":[4,2,3,7,6],"longest":10,"segments":[[3,11],[15,17],[19,26],[29,37],[44,54],[60,62]]}
312
def f312(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[0])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
work = [(row, col)]
visited.add((row, col))
while work:
cur = work.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
work.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f312(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
313
def f313(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {normalize(value) for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
listing = sorted
returnvalue = {'both': listing(both), 'left': listing(a - b), 'right': listing(b - a), 'all': listing(a | b), 'score': sum((min(len(value), 8) for value in both))}
output = dict()
output.update(returnvalue)
return output
f313(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
314
def f314(spans, gap):
spans = list(spans)
segments = []
for left, right in sorted(spans):
if not segments or left > segments[-1][1] + gap:
segments.append([left, right])
else:
segments[-1][1] = max(0, segments[-1][1], right)
breaks = []
for pos in range(1, len(segments)):
left = segments[pos][0]
breaks.append(left - segments[pos - 1][1])
returnvalue = {'segments': segments, 'cover': sum((right - left for left, right in segments)), 'holes': breaks, 'longest': min(100, max((right - left for left, right in segments)))}
output = dict()
output.update(returnvalue)
return output
f314([(3, 6), (6, 11), (15, 17), (19, 26), (29, 34), (34, 37), (44, 50), (49, 54), (60, 62)], 3)
{"cover":42,"holes":[4,7,6],"longest":22,"segments":[[3,11],[15,37],[44,54],[60,62]]}
315
def f315(left, right, excluded):
left = list(left)
def normalize(value):
return str(value).strip(' \n').upper()
excluded = {str(value).upper() for value in excluded}
a = {normalize(value) for value in left} - excluded
b = {normalize(value) for value in right} - excluded
both = a & b
sequence = sorted
returnvalue = {'both': sequence(both), 'left': sequence(a - b), 'right': sequence(b - a), 'all': sequence(a | b), 'score': sum((len(value) for value in both))}
output = dict()
output.update(returnvalue)
return output
f315(['GARNET', 'ivory', 'BLUE', 'cyan ', ' Amber', 'helium', 'Ember'], [' Amber', 'helium', 'cyan ', 'ivory', 'Ember', 'BLUE', 'Ember'], ['Ember'])
{"all":["AMBER","BLUE","CYAN","GARNET","HELIUM","IVORY"],"both":["AMBER","BLUE","CYAN","HELIUM","IVORY"],"left":["GARNET"],"right":[],"score":24}
316
def f316(left, right, fee):
left = list(left)
ratemap = {}
for name0, rate0 in right[:20]:
if name0 not in ratemap:
ratemap[name0] = rate0
matched = []
for key, count in left:
if key in ratemap:
matched.append((key, count * ratemap[key] + fee))
matched.sort(key=lambda item: (-item[1], item[0]))
leftover = sorted((key for key, count in left if key not in ratemap))
returnvalue = {'items': [[key, value] for key, value in matched[:5]], 'total': sum((value for key, value in matched)), 'missing': leftover, 'count': len({key for key, value in matched})}
output = dict()
output.update(returnvalue)
return output
f316([('AN', 5), ('BR', 8), ('CX', 11), ('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)], [('AN', 5), ('BR', 6), ('CX', 8), ('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)], 2)
{"count":8,"items":[["CX",90],["BR",50],["DL",46],["GQ",42],["FP",34]],"missing":[],"total":313}
317
def f317(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
needs = {node: 0 for node in nodes}
children = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
children[a].append(b)
needs[b] += 1
startdegree = dict(needs)
complete = set()
sequence = []
groups = []
while len(complete) < len(nodes):
nextbatch = sorted((node for node in nodes if needs[node] == 0 and node not in complete), reverse=len(nodes) > 20)
if not nextbatch:
break
current = nextbatch
groups.append(current)
for node in current:
complete.add(node)
sequence.append(node)
for node in current:
for nxt in children[node]:
needs[nxt] -= 1
returnvalue = {'order': sequence, 'batches': groups, 'roots': sorted((node for node in nodes if startdegree[node] == 0)), 'count': len(sequence)}
output = dict()
output.update(returnvalue)
return output
f317(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth')])
{"batches":[["cache","db"],["auth","jobs"],["api","proxy","worker"],["ui"]],"count":8,"order":["cache","db","auth","jobs","api","proxy","worker","ui"],"roots":["cache","db"]}
318
def f318(nodes, edges):
nodes = list(nodes)
nodes = [node for node in nodes if node not in nodes or any((node in edge for edge in edges))]
indegree = {node: 0 for node in nodes}
nextmap = {node: [] for node in nodes}
for before, after in edges:
if before == after:
continue
a, b = (before, after)
nextmap[a].append(b)
indegree[b] += 1
initial = dict(indegree)
handled = set()
result = []
layers = []
while len(handled) < len(nodes):
available = sorted((node for node in nodes if indegree[node] == 0 and node not in handled), reverse=any((str(node).isupper() for node in nodes)))
if not available:
break
current = available
layers.append(current)
for node in current:
handled.add(node)
result.append(node)
for node in current:
for nxt in nextmap[node]:
indegree[nxt] -= 1
returnvalue = {'order': result, 'batches': layers, 'roots': sorted((node for node in nodes if initial[node] == 0)), 'count': len(result)}
output = dict()
output.update(returnvalue)
return output
f318(['auth', 'worker', 'proxy', 'ui', 'api', 'jobs', 'cache', 'db'], [('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs'), ('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache')])
{"batches":[["auth","db"],["cache","jobs","proxy"],["api","worker"],["ui"]],"count":8,"order":["auth","db","cache","jobs","proxy","api","worker","ui"],"roots":["auth","db"]}
319
def f319(board):
board = list(board)
visited = set()
components = []
for row in range(min(len(board), 10 + (len(board) - len(board)))):
for col in range(len(board[0])):
if board[row][col] != '#' or (row, col) in visited:
continue
cells = []
queue = [(row, col)]
visited.add((row, col))
while queue:
cur = queue.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
if len(visited) >= 100:
continue
queue.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f319(['...##.', '.##...', '.#.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,1],[2,3],[0,3],[5,3]],"count":4,"filled":16,"sizes":[7,6,2,1]}
320
def f320(board):
board = list(board)
visited = set()
components = []
for row in range(len(board)):
for col in range(len(board[row])):
if col >= 12 or board[row][col] != '#' or (row, col) in visited:
continue
cells = []
pending = [(row, col)]
visited.add((row, col))
while pending:
cur = pending.pop()
cells.append(cur)
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nxt = (cur[0] + dr, cur[1] + dc)
if 0 <= nxt[0] < len(board) and 0 <= nxt[1] < len(board[nxt[0]]) and (nxt[1] < 12) and (board[nxt[0]][nxt[1]] == '#') and (nxt not in visited):
visited.add(nxt)
pending.append(nxt)
components.append((len(cells), min(cells)))
components.sort(key=lambda item: (-item[0], item[1]))
returnvalue = {'sizes': [size for size, anchor in components], 'anchors': [list(anchor) for size, anchor in components], 'filled': sum((size for size, anchor in components)), 'count': len(components)}
output = dict()
output.update(returnvalue)
return output
f320(['...###', '###..#', '##.##.', '.#..#.', '.##.##', '.#.#.#'])
{"anchors":[[1,0],[2,3],[0,3],[5,3]],"count":4,"filled":20,"sizes":[9,6,4,1]}
Final Query
Give me the output of the final query without executing it!
import json, re
from collections import deque
out = {}
board = list(('...###', '###..#') + ('##.##.', '.#..#.', '.##.##', '.#.#.#'))
cells = [(row, col) for row in range(len(board)) for col in range(len(board[row])) if board[row][col] == '#']
parent = {cell: cell for cell in cells}
def root(cell):
while parent[cell] != cell:
parent[cell] = parent[parent[cell]]
cell = parent[cell]
return cell
def merge(a, b):
a = root(a)
b = root(b)
if a != b:
parent[b] = a
for row, col in cells:
for other in ((row - 1, col), (row, col - 1)):
if other in parent:
merge((row, col), other)
groups = {}
for cell in cells:
groups.setdefault(root(cell), []).append(cell)
parts = [(len(group), min(group)) for group in groups.values()]
parts.sort(key=lambda item: (-item[0], item[1]))
record = {'aa': [part[0] for part in parts], 'bb': [list(part[1]) for part in parts], 'cc': len(cells), 'dd': len(parts)}
permit = record['cc']
rows = list((('AN06', 'core', 'ready', 9), ('DL43', 'core', 'hold', 6), ('CX80', 'north', 'void', 11), ('CX17', 'south', 'void', 4), ('BR54', 'north', 'checked', 9), ('CX91', 'core', 'ready', 16), ('AN28', 'edge', 'checked', 13), ('AN65', 'edge', 'hold', 9)) + (('BR02', 'south', 'ready', 12), ('AN39', 'south', 'ready', 10), ('CX76', 'south', 'ready', 4), ('AN13', 'core', 'hold', 4), ('CX50', 'edge', 'ready', 14), ('DL87', 'edge', 'void', 4)))
keep = list(('ready',) + ('checked',))
route = permit
cases = {
16: dict((('north', 10), ('south', 5), ('core', 11)) + (('edge', 3),)),
20: dict((('north', 7), ('south', 9), ('core', 11)) + (('edge', 3),)),
}
rates = cases[route]
chosen = [(code, group, value) for code, group, state, value in rows if state in keep]
priced = [(code, group, value * rates[group]) for code, group, value in chosen]
groups = {}
for code, group, price in priced:
groups[group] = groups.get(group, 0) + price
ranked = sorted(priced, key=lambda row: (-row[2], row[0]))
record = {'aa': [row[0] for row in ranked[:3]], 'bb': sum((row[2] for row in priced)), 'cc': len(priced), 'dd': groups}
signal = record['bb']
spans = list(((3, 6), (6, 11), (15, 17), (19, 26)) + ((29, 34), (34, 37), (44, 50), (49, 54), (60, 62)))
gap = 0
spans.sort(key=lambda pair: (pair[0], pair[1]))
parts = []
pos = 0
while pos < len(spans):
left, right = spans[pos]
pos += 1
while pos < len(spans) and spans[pos][0] <= right + gap:
right = max(right, spans[pos][1])
pos += 1
parts.append([left, right])
holes = [parts[pos][0] - parts[pos - 1][1] for pos in range(1, len(parts))]
record = {'aa': parts, 'bb': holes, 'cc': sum((part[1] - part[0] for part in parts)), 'dd': max((part[1] - part[0] for part in parts))}
token = record['cc']
width = 3
limit = 58
route = token
cases = {
42: list((15, 13, 21, 17, 20, 11) + (22, 13, 18, 6, 6, 17, 21, 7, 18)),
37: list((15, 13, 21, 17, 20, 11) + (22, 10, 18, 11, 6, 17, 21, 7, 18)),
}
values = cases[route]
current = sum(values[:width])
sums = [current]
for pos in range(width, len(values)):
current += values[pos] - values[pos - width]
sums.append(current)
hits = []
rises = 0
for pos, value in enumerate(sums):
if value >= limit:
hits.append(pos)
if pos and value > sums[pos - 1]:
rises += 1
record = {'aa': hits, 'bb': max(sums), 'cc': rises, 'dd': sums}
memo = record['dd'][5]
left = list(('GARNET', 'ivory', 'BLUE', 'cyan ') + (' Amber', 'helium', 'Ember'))
right = list((' Amber', 'helium', 'cyan ', 'ivory') + ('Ember', 'BLUE', 'Ember'))
route = memo
cases = {
43: ['Ember'],
46: ['GARNET'],
}
blocked = cases[route]
a = set()
b = set()
ban = set()
for value in blocked:
ban.add(value.strip().upper())
for value in left:
value = value.strip().upper()
if value not in ban:
a.add(value)
for value in right:
value = value.strip().upper()
if value not in ban:
b.add(value)
both = a.intersection(b)
record = {'aa': sorted(both), 'bb': sorted(a.difference(b)), 'cc': sorted(b.difference(a)), 'dd': sorted(a.union(b)), 'ee': sum(map(len, both))}
clue = record['ee']
stop = ['garnet']
route = (signal, clue)
cases = {
(576, 29): list(('Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost') + ('Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet')),
(576, 24): list(('Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost') + ('Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet')),
(653, 29): list(('Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost') + ('Amber, delta. ember delta ember', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue quartz', 'Amber, ember. cyan garnet')),
(653, 24): list(('Blue, amber. frost blue', 'Amber, ember. blue blue helium', 'Garnet, blue. ember frost') + ('Amber, delta. ember delta ember vivid', 'Ember, blue. cyan frost', 'Ember, ember. blue frost blue', 'Amber, ember. cyan garnet')),
}
lines = cases[route]
normalized = set()
for item in stop:
normalized.add(item.lower())
stop = normalized
words = []
for line in lines:
words.extend(re.findall('[a-z]+', line.lower()))
words = [word for word in words if word not in stop]
counts = {}
initials = {}
for word in words:
counts[word] = counts.get(word, 0) + 1
initials[word[0]] = initials.get(word[0], 0) + 1
top = sorted(counts, key=lambda word: (-counts[word], word))[:5]
record = {'aa': top, 'bb': counts, 'cc': initials, 'dd': sum((len(word) for word in words))}
stamp = record['dd']
left = list((('AN', 5), ('BR', 8), ('CX', 11)) + (('DL', 11), ('EV', 2), ('FP', 8), ('GQ', 10), ('HR', 2)))
right = list((('AN', 5), ('BR', 6), ('CX', 8)) + (('DL', 4), ('EV', 4), ('FP', 4), ('GQ', 4), ('HR', 6)))
route = stamp
cases = {
141: 2,
142: 3,
}
fee = cases[route]
joined = []
for key, count in left:
matches = [rate for name, rate in right if name == key]
if matches:
joined.append([key, count * matches[0] + fee])
joined.sort(key=lambda item: (-item[1], item[0]))
rightkeys = {key for key, rate in right}
record = {'aa': joined[:5], 'bb': sum((item[1] for item in joined)), 'cc': sorted((key for key, count in left if key not in rightkeys)), 'dd': len(joined)}
ticket = record['bb']
nodes = list(('auth', 'worker', 'proxy', 'ui', 'api') + ('jobs', 'cache', 'db'))
route = ticket
cases = {
321: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('cache', 'auth'))),
313: list((('auth', 'api'), ('db', 'api'), ('cache', 'api'), ('api', 'ui'), ('db', 'jobs')) + (('jobs', 'worker'), ('auth', 'proxy'), ('db', 'cache'))),
}
edges = cases[route]
remaining = set(nodes)
done = set()
order = []
batches = []
while remaining:
ready = sorted((node for node in remaining if all((before in done for before, after in edges if after == node))))
if not ready:
break
batches.append(ready)
order.extend(ready)
done.update(ready)
remaining.difference_update(ready)
roots = sorted((node for node in nodes if all((after != node for before, after in edges))))
record = {'aa': order, 'bb': batches, 'cc': roots, 'dd': len(order)}
out['aa'] = record['aa']
out['bb'] = record['bb']
out['cc'] = record['cc']
out['dd'] = record['dd']
print(json.dumps(out, separators=(",", ":"), sort_keys=True))