Skip to content

Instantly share code, notes, and snippets.

View knkillname's full-sized avatar

Mario Abarca knkillname

View GitHub Profile
##Calculadora humana. Por knkillname.
##¡Diviértete!
from random import choice, randint
L = ['+', '-', '×', '/']
while True:
op = choice(L)
if op == '+':
res = randint(1, 99)
a = randint(0, res)
@knkillname
knkillname / caminos.py
Last active May 5, 2020 17:39
Algoritmos de optimización combinatoria
## Algoritmos de caminos más cortos
from estructuras import Cola, ColaMin
from conectividad import ordenamiento_topologico
inf = float('inf') #Tratar infinito como un numero
def recorrido_a_lo_ancho(G, s):
dist, padre = {v:inf for v in G}, {v:v for v in G}
dist[s] = 0
@knkillname
knkillname / programs.py
Last active April 7, 2019 05:15
Generate all posible programs
# This program prints all the programs that can be written in Python
# (even this very same program if you give it enough time)
import string
def generate_programs(alphabet = string.printable):
alphabet = tuple(alphabet)
word, m, n = [], 0, len(alphabet)
while True:
p = ''.join(alphabet[i] for i in word)
import ast
## ESTRUCTURA DE DATOS PARA ALMACENAR UN CIRCUITO BOOLEANO
class Nodo:
__slots__ = 'etiqueta', 'hijos'
def __init__(self, etiqueta, *hijos):
self.etiqueta = etiqueta
self.hijos = hijos
## Author: Mario Abarca (knkillname)
## Email: asma@uaem.mx
## Date: 25 Feb 2015
## Language: Python 3
##
## Summary: A class representing bigraph objects given by a quasi-Cartan
## Matrix. Includes elementary operations, csv formating, and ploting.
from array import array
from os.path import splitext
@knkillname
knkillname / algsenredes.py
Last active October 20, 2015 17:20
Algoritmos del curso básico de Algoritmia
## Algoritmos en redes (grafos con pesos en las aristas)
##
## Autor: Mario Abarca (asma@uaem.mx)
## Fecha: 20 de octubre de 2015
from grafos import Grafo
from estructuras import Cola
from estructuras import ColaMin
from estructuras import ConjuntosDisjuntos
import turtle, colorsys, math
t = turtle.Turtle()
t.pensize(4); t.right(90); t.speed(0)
n, j, i, p = 19, 1, 1, (5 ** 0.5 - 1) / 2
for k in range(n):
r, g, b = colorsys.hls_to_rgb(p * k % 1, p, 1)
t.color('white', (r, g, b))
t.begin_fill()
for k in range(4):
## A simple program that showcases tree drawing by fractals
## Copyright (C) 2016 Mario Abarca
##
## This program is free software: you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation, either version 3 of the
## License, or (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
@knkillname
knkillname / laberinto.py
Created October 31, 2017 17:58
Laberinto por recorrido en profundidad en Python 3
# Crear un laberinto aleatorio en Python3 usando el algoritmo de
# recorrido en profundidad. El propósito de este programa es mostrar las
# características del lenguaje.
#
# Autor: Mario Abarca
# Fecha: 2017/09/07
from random import shuffle, randint # Números pseudoaleatorios
from itertools import product # Producto cartesiano
@knkillname
knkillname / textobinario.py
Last active October 29, 2023 19:54
Convertir texto a binario y viceversa.
# Autor: Mario Abarca
# Fecha: 29 nov. 2017
# Lenguaje: Python 3.6
from cmd import Cmd
class TextoBinarioApp(Cmd):
def __init__(mi):
super().__init__()
mi.codigo = 'utf8'