Add files via upload

This commit is contained in:
Peter Norvig 2024-12-26 01:35:10 -08:00 committed by GitHub
parent e1bd865098
commit 69cc3ce239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 1522 additions and 300 deletions

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@
"source": [
"from collections import Counter, defaultdict, namedtuple, deque, abc\n",
"from dataclasses import dataclass, field\n",
"from itertools import permutations, combinations, cycle, chain, islice\n",
"from itertools import permutations, combinations, cycle, chain, islice, filterfalse\n",
"from itertools import count as count_from, product as cross_product, takewhile\n",
"from typing import *\n",
"from statistics import mean, median\n",
@ -173,7 +173,6 @@
"outputs": [],
"source": [
"answers = {} # `answers` is a dict of {puzzle_number: answer}\n",
"\n",
"unknown = 'unknown'\n",
"\n",
"class answer:\n",
@ -754,7 +753,12 @@
" \n",
"class HCounter(Counter):\n",
" \"\"\"A Counter, but it is hashable.\"\"\"\n",
" def __hash__(self): return hash(tuple(sorted(self.items())))"
" def __hash__(self): return hash(tuple(sorted(self.items())))\n",
"\n",
"class EqualityIsIdentity:\n",
" \"\"\"A mixin to say that objects of this class are equal only if they are identical.\"\"\"\n",
" def __hash__(self): return id(self)\n",
" def __eq__(self, other): return self is other"
]
},
{
@ -766,7 +770,7 @@
"class Graph(defaultdict):\n",
" \"\"\"A graph of {node: [neighboring_nodes...]}. \n",
" Can store other kwd attributes on it (which you can't do with a dict).\"\"\"\n",
" def __init__(self, contents, **kwds):\n",
" def __init__(self, contents=(), **kwds):\n",
" self.update(contents)\n",
" self.default_factory = list\n",
" self.__dict__.update(**kwds)"