This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
SPOILER ALERT | |
As usual, these are snippets used to get the answer in interactive mode, not | |
a self-contained interactive program. | |
""" | |
class Monkey: | |
monkeys = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Puzzles at: https://adventofcode.com/2022/day/8 | |
SPOILER ALERT!!! | |
Not super-smart - but very conffy to look and operate at the map. | |
Probably with some heavy caching (using attached dicts) could go from quadractic time to near linear time. | |
(Or O(MxN) M being the total points, N being max (Width, Height)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Problem at https://adventofcode.com/2022/day/6 | |
SPOILER ALERT! | |
This is a problem that could easily be solved by "brute-force" and simply | |
creating a set for each 14-character window and checking its length. | |
I created a "counter of counters" that I think could hold | |
constant time for counting, and therefore, linear time to | |
find large un-repeated sequences in large (multi GB) datasets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
( https://adventofcode.com/2022/day/5 ) | |
SPOILER ALERT! | |
Instead of the end-to-end solution, just the class I've used | |
which can display the animation of containers been | |
moved around - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
( https://adventofcode.com/2022/day/4 ) | |
SPOILER ALERT! The snippets in here present a complete solution | |
This is both "my style" and what I like most about Python: | |
creating a minimal class which implements one or more operators | |
turns the solving of thiz puzzle into a super-readable | |
one liner! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script type="text/javascript" src="brython.js"></script> | |
<script type="text/javascript" src="brython_stdlib.js"></script> | |
</head> | |
<body onload="brython(1)"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv | |
from terminedia import getch | |
MEMSIZE = 8192 | |
def main(): | |
program = open(argv[1]).read() | |
memory = bytearray(MEMSIZE) | |
pointer = 0 | |
program_counter = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Comparator: | |
def __init__(self, value, stage): | |
self.value = value | |
self.stage = stage | |
def __eq__(self, other): | |
return self.value >= other if self.stage == "start" else self.value < other | |
class Interval: | |
__match_args__ = ("start", "stop") | |
def __init__(self, value): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<body> | |
<img src="bla2.svg"> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Um pouco de história do #Python: a "mudadora de mundo: versão 2.2, um fio: | |
Há pouco mais de 20 anos, em 21 de dezembro de 2001, foi lançada a versão 2.2 do Python. Essa provavelmente foi a versão mais importante da linguagem, fora a versão "3.0" em si, com muito pouca quebra de compatibilidade. | |
I) A principal mudança: a chegada das "New Style Classes", com as quais as classes criadas em Python passaram a ser "cidadãs de primeira classe". Antes disso, existiam "classes" criadas em Python e os "types", os tipos nativos da linguagem, como int, list, float - as duas coisas não se conversavam - | |
PEP 252 -- Making Types Look More Like Classes -- https://www.python.org/dev/peps/pep-0252/ | |
PEP 253 -- Subtyping Built-in Types -- https://www.python.org/dev/peps/pep-0253/ | |
As new style classes além da unificação de tipos, trouxeram: | |
1. o "descriptor protocol" o protocolo interno que até hoje é responsável |