[dependencies]
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
[
{
"values": {
"test_snap": "test_snap2",
"15:49:28": "09:38:39",
"no-description": "no-description",
"`->": "`->",
"2023-12-15": "2023-12-22"
},
"children": [
{
"values": {
"no-description": "no-description",
"test_snap": "snapshot3",
"`->": "`->",
"2023-12-15": "2023-12-22",
"15:49:28": "09:38:54"
},
"children": [
{
"values": {
"`->": "`->",
"15:49:28": "09:39:03",
"2023-12-15": "2023-12-22",
"no-description": "no-description",
"test_snap": "xxx"
},
"children": [
{
"values": {
"test_snap": "current",
"`->": "`->",
"2023-12-15": "You",
"15:49:28": "are",
"no-description": "here!"
},
"children": []
}
]
}
]
}
]
}
]
_ name date time description
`-> test_snap 2023-12-15 15:49:28 no-description
`-> test_snap2 2023-12-22 09:38:39 no-description
`-> snapshot3 2023-12-22 09:38:54 no-description
`-> xxx 2023-12-22 09:39:03 no-description
`-> current You are here!
[
{
"values": {
"name": "test_snap",
"time": "15:49:28",
"description": "no-description",
"date": "2023-12-15",
"_": "`->"
},
"children": [
{
"values": {
"name": "test_snap2",
"description": "no-description",
"time": "09:38:39",
"_": "`->",
"date": "2023-12-22"
},
"children": [
{
"values": {
"date": "2023-12-22",
"_": "`->",
"time": "09:38:54",
"description": "no-description",
"name": "snapshot3"
},
"children": [
{
"values": {
"_": "`->",
"date": "2023-12-22",
"time": "09:39:03",
"name": "xxx",
"description": "no-description"
},
"children": [
{
"values": {
"date": "You",
"time": "are",
"description": "here!",
"_": "`->",
"name": "current"
},
"children": []
}
]
}
]
}
]
}
]
}
]
def solve(buckets: list[frozenset[int]], pool: frozenset[int], sum_: int, solved: set[frozenset[frozenset[int]]], tried: set[frozenset[frozenset[int]]]):
assert all(x <= sum_ for x in pool)
tried.add(frozenset(buckets))
if not pool and set(sum(bucket) for bucket in buckets) == {sum_} and len(set(len(b) for b in buckets)) == 1:
solved.add(frozenset(buckets))
for x in pool:
for i, bucket in enumerate(buckets):
new_buckets = buckets[:]
new_buckets[i] = bucket | {x}
if frozenset(new_buckets) not in tried:
solve(new_buckets, pool - {x}, sum_, solved, tried)
return solved
if __name__ == '__main__':
for solution in solve([frozenset(), frozenset()], frozenset([1,2,3,4,5,6,7,8]), 18, set(), set()):
print(solution)
("й", "y", "ц", "mq", "у", "mx", ...)
) и получить сложность O(N) и сэкономить примерно 600 байт (т.к. кортеж на 66 элементов занимает примерно 600 байт), но содержимое у тебя никуда не денется. Ты даже можешь отсортировать пары по ключу и искать бинарным поиском за O(logN) "на халяву"import base64
text = 'eyJzaWQiOiJmYVVGVjBpTVo2OTRpY3BTVnhsMGJNbzBaUEJGTmcyWiIsImFpZCI6bnVsbCwiZXhwIjoxNjY3MTQ4NTQyfQ'
print(base64.b64decode(text + "=="))