A curated list of my GitHub stars! Generated by starred.
This file contains hidden or 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
| #!/bin/env python | |
| import requests | |
| import sys | |
| if len(sys.argv) != 2: | |
| print("Falta 1 argumento de entrada") | |
| sys.exit(1) | |
| arg = sys.argv[1] |
¡Excelente iniciativa! Usar Scala 3, con su potente sistema de tipos (incluyendo traits, intersection types, extension methods, context functions y given/using), es una forma muy elegante y rigurosa de formalizar conceptos algebraicos. El enfoque de "type classes" encaja perfectamente aquí.
El repositorio que mencionas parece un buen punto de partida, probablemente definiendo estructuras básicas como Semigrupos, Monoides y Grupos. Para continuar y definir estructuras más complejas como los anillos, seguirías construyendo sobre esas bases.
Cómo Continuar - Pasos Generales:
- Jerarquía de Traits: Define cada estructura algebraica como un
trait. Las estructuras más complejas heredarán (extends) de las más simples. Por ejemplo, unRingextenderá (de alguna forma) las propiedades de unAbelianGroup(para la suma) y unMonoid(para la multiplicación). - Métodos y Operadores: Usa
extension methodsdentro de los traits para definir las operaciones binarias (+, *) y unarias (-) de
This file contains hidden or 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
| def benchmarks[A](f: => A) = | |
| inline def memory() = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() | |
| val t0 = System.nanoTime() | |
| val m0 = memory() | |
| val ret = f | |
| val t1 = System.nanoTime() | |
| val m1 = memory() |
This file contains hidden or 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
| import numpy as np | |
| import sys | |
| sys.set_int_max_str_digits(0) | |
| def matrix_power(A: np.matrix, n: int) -> np.matrix: | |
| if n == 0: | |
| return np.matrix( ((1,0),(0,1)), dtype=object ) | |
| elif n%2 == 1: |
This file contains hidden or 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
| import time | |
| import functools | |
| def timer_decorator(func): | |
| @functools.wraps(func) | |
| def wrapper(*args, **kwargs): | |
| start = time.time_ns() | |
| res = func(*args, **kwargs) | |
| end = time.time_ns() | |
| wrapper.last_execution_time = end - start |
This file contains hidden or 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
| val fibs: LazyList[BigInt] = BigInt(1) #:: BigInt(1) #:: (fibs zip fibs.tail).map(_+_) | |
| val fibs: LazyList[BigInt] = 1 #:: fibs.scan(BigInt(1))(_+_) | |
| val lucas: LazyList[BigInt] = 2 #:: fibs.scan(BigInt(1))(_+_) |
This file contains hidden or 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 pathlib import WindowsPath | |
| class LongPath(WindowsPath): | |
| uncprefix = "\\\\?\\" | |
| def __new__(cls, *pathsegments): | |
| ins = super().__new__(cls, *pathsegments) | |
| abspath = ins.expanduser().absolute() | |
| match abspath.parts: | |
| case (drive, *parts) if not drive.startswith(cls.uncprefix): |
This file contains hidden or 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 itertools import count, takewhile | |
| def calc_pi(error: float = 1e-6) -> float: | |
| terms = (1 / (2 * k - 1) for k in count(1)) | |
| it = takewhile(lambda x: 2 * x >= error, terms) | |
| ts = list(x - y for x, y in zip(it, it)) | |
| pi = 4 * sum(ts) | |
| calc_pi.error = error |
This file contains hidden or 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
| import sys | |
| from bisect import bisect, bisect_left | |
| from collections.abc import Generator, Iterable, Iterator | |
| from functools import singledispatchmethod | |
| from itertools import islice | |
| from math import isqrt | |
| INFINITE = sys.maxsize # una mala aproximación de infinito | |
| Prime = int # un alias para los primos |
NewerOlder