Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jsbueno
jsbueno / day11_2022.py
Created December 12, 2022 22:35
Advent of code 2022, day 11
"""
SPOILER ALERT
As usual, these are snippets used to get the answer in interactive mode, not
a self-contained interactive program.
"""
class Monkey:
monkeys = []
@jsbueno
jsbueno / day8.py
Last active December 8, 2022 19:39
Advent of code 2022, day8
"""
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))
@jsbueno
jsbueno / gist:19490688b6f001cfd5ba691d6e69c9e3
Created December 6, 2022 21:43
Advent of code 2022 day 6 , Dec 6-
"""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
@jsbueno
jsbueno / day5.py
Created December 5, 2022 20:29
Advent of code, 5, Dec 2022
"""
( 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 -
@jsbueno
jsbueno / day4.py
Last active December 5, 2022 19:02
Advent of code, dec, 4th 2022, parts 1 and 2
"""
( 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!
@jsbueno
jsbueno / index.html
Created November 14, 2022 15:47
brython "hello world" showing the easy-to use DOM integration that is lacking on other python-on-browsers.
<!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)">
@jsbueno
jsbueno / brainfuck.py
Last active October 8, 2022 05:05
brainfuck
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
@jsbueno
jsbueno / range_matcher.py
Last active June 28, 2022 01:05
Python match/case internals "hacky" class which allows one to match ranges without needing any expression guards
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):
@jsbueno
jsbueno / bla1.html
Last active April 20, 2022 03:25
How to manipulate an SVG image in a document that is loaded in an <img > tag.
<!DOCTYPE html>
<html>
<body>
<img src="bla2.svg">
</body>
</html>
@jsbueno
jsbueno / gist:7e482a67098ac0ccc9eb560a27d6f521
Created March 8, 2022 02:55
Novidades e tecnologias na versão 2.2 do Python
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