Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 35 additions & 14 deletions js/react-scrolling/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions js/react-scrolling/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6872,14 +6872,14 @@ react-dev-utils@^7.0.1:
strip-ansi "4.0.0"
text-table "0.2.0"

[email protected]:
version "16.7.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.7.0.tgz#a17b2a7ca89ee7390bc1ed5eb81783c7461748b8"
react-dom@^16.7.0:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.14.0.tgz#7ad838ec29a777fb3c75c3a190f661cf92ab8b89"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.12.0"
scheduler "^0.19.1"

react-error-overlay@^5.1.2:
version "5.1.2"
Expand Down Expand Up @@ -6939,14 +6939,13 @@ [email protected]:
optionalDependencies:
fsevents "1.2.4"

[email protected]:
version "16.7.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.7.0.tgz#b674ec396b0a5715873b350446f7ea0802ab6381"
react@^16.7.0:
version "16.14.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.14.0.tgz#94d776ddd0aaa37da3eda8fc5b6b18a4c9a3114d"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
prop-types "^15.6.2"
scheduler "^0.12.0"

read-pkg-up@^1.0.1:
version "1.0.1"
Expand Down Expand Up @@ -7346,9 +7345,9 @@ saxes@^3.1.4:
dependencies:
xmlchars "^1.3.1"

scheduler@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.12.0.tgz#8ab17699939c0aedc5a196a657743c496538647b"
scheduler@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.19.1.tgz#4f3e2ed2c1a7d65681f4c854fa8c5a1ccb40f196"
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
Expand Down Expand Up @@ -7996,8 +7995,8 @@ tmp@^0.0.33:
os-tmpdir "~1.0.2"

[email protected]:
version "1.0.4"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
version "1.0.5"
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.5.tgz#8683e0b902bb9c20c4f726e3c0b69f36518c07cc"

to-arraybuffer@^1.0.0:
version "1.0.1"
Expand Down
65 changes: 65 additions & 0 deletions py/advent-of-code-2017/common/knot_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from functools import reduce
from operator import xor
from typing import Iterable, List


class Circle:
def __init__(self, values: Iterable[int]):
self.__values = list(values)

def normalize_index(self, index: int) -> int:
return index % len(self.__values)

def swap(self, i: int, j: int) -> None:
i = self.normalize_index(i)
j = self.normalize_index(j)
self.__values[i], self.__values[j] = self.__values[j], self.__values[i]

def __getitem__(self, item: int) -> int:
return self.__values[self.normalize_index(item)]

def __str__(self):
return str(self.__values)

def values(self) -> List[int]:
return self.__values.copy()


def reverse(circle: Circle, start: int, length: int) -> None:
end = circle.normalize_index(start + length - 1)
for i in range(length // 2):
circle.swap(start + i, end - i)


def hash_round(circle: Circle, lengths: List[int], position: int = 0, skip: int = 0) -> tuple[int, int]:
for length in lengths:
reverse(circle, position, length)
position = circle.normalize_index(position + length + skip)
skip += 1
return position, skip


def hash_blocks(values: List[int]) -> List[int]:
result = [0] * 16

for i in range(16):
start, end = i * 16, (i + 1) * 16
result[i] = reduce(xor, values[start:end])

return result


def hexify(x: int) -> str:
hexed = hex(x)[2:]
return hexed if len(hexed) == 2 else '0' + hexed


def get_knot_hash(s: str) -> str:
circle = Circle(range(256))
lengths = [ord(c) for c in s] + [17, 31, 73, 47, 23]
position, skip = 0, 0
for _ in range(64):
position, skip = hash_round(circle, lengths, position, skip)

hashed_blocks = hash_blocks(circle.values())
return ''.join(map(hexify, hashed_blocks))
67 changes: 5 additions & 62 deletions py/advent-of-code-2017/day10.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,16 @@
from typing import List, Iterable
from functools import reduce
from operator import xor
from typing import List


class Circle:
def __init__(self, values: Iterable[int]):
self.__values = list(values)

def normalize_index(self, index: int) -> int:
return index % len(self.__values)

def swap(self, i: int, j: int) -> None:
i = self.normalize_index(i)
j = self.normalize_index(j)
self.__values[i], self.__values[j] = self.__values[j], self.__values[i]

def __getitem__(self, item: int) -> int:
return self.__values[self.normalize_index(item)]

def __str__(self):
return str(self.__values)

def values(self) -> List[int]:
return self.__values.copy()


def reverse(circle: Circle, start: int, length: int) -> None:
end = circle.normalize_index(start + length - 1)
for i in range(length // 2):
circle.swap(start + i, end - i)


def hash_round(circle: Circle, lengths: List[int], position: int = 0, skip: int = 0) -> tuple[int, int]:
for length in lengths:
reverse(circle, position, length)
position = circle.normalize_index(position + length + skip)
skip += 1
return position, skip
from common.knot_hash import Circle, hash_round, get_knot_hash


def part1(circle: Circle, lengths: List[int]) -> int:
hash_round(circle, lengths)
return circle[0] * circle[1]


def hash_blocks(values: List[int]) -> List[int]:
result = [0] * 16

for i in range(16):
start, end = i * 16, (i + 1) * 16
result[i] = reduce(xor, values[start:end])

return result


def hexify(x: int) -> str:
hexed = hex(x)[2:]
return hexed if len(hexed) == 2 else '0' + hexed


def part2(circle: Circle, lengths_string: str):
lengths = [ord(c) for c in lengths_string] + [17, 31, 73, 47, 23]
position, skip = 0, 0
for _ in range(64):
position, skip = hash_round(circle, lengths, position, skip)

hashed_blocks = hash_blocks(circle.values())
return ''.join(map(hexify, hashed_blocks))
def part2(lengths_string: str):
return get_knot_hash(lengths_string)


print(part1(Circle(range(256)), [129, 154, 49, 198, 200, 133, 97, 254, 41, 6, 2, 1, 255, 0, 191, 108]))
print(part2(Circle(range(256)), '129,154,49,198,200,133,97,254,41,6,2,1,255,0,191,108'))
print(part2('129,154,49,198,200,133,97,254,41,6,2,1,255,0,191,108'))
Loading