Skip to content

Instantly share code, notes, and snippets.

View davidsonbrsilva's full-sized avatar

Davidson Bruno davidsonbrsilva

View GitHub Profile
name: transposer
source code: |-
input: '++++'
blank: ' '
start state: D
table:
'Gbb':
' ': {R: 'F'}
'+': {R: 'Gb'}
'-': {R: 'Fb'}
@davidsonbrsilva
davidsonbrsilva / main.py
Created June 10, 2019 01:06
Generic unit test function
from sample import reverse, add, mult, is_adult, compare
from unittest import test
# Testing reverse function
test("olleh", reverse, "hello")
test("ababa", reverse, "hello")
# Testing add function
test(10, add, 2, 3, 5)
test(10, add, 2, 3, 4)
@davidsonbrsilva
davidsonbrsilva / hufzip-build-bytes.cpp
Created May 27, 2019 12:22
Método de construção de bytes comprimidos de Hufzip.
string Huff::buildBytes(string bitflow)
{
unsigned char byte = 0;
unsigned int currbit = 0;
std::string output = "";
while (currbit < bitflow.size())
{
// Concatena o byte construído a cada 8 bits lidos.
for (int i = 0; i < BYTE_SIZE; )
@davidsonbrsilva
davidsonbrsilva / optimal.py
Created March 31, 2019 23:36
Implementação de testes de primalidade: optimal
def optimal(number):
if number >= 2:
# Calcula a raiz quadrada de number
sqrt_n = int(math.sqrt(number) + 1)
for index in range(2, sqrt_n):
# Se houver algum divisor entre 1 (exclusive) e a raiz quadrada de number, number não é primo.
@davidsonbrsilva
davidsonbrsilva / fermat.py
Last active April 5, 2019 14:56
Implementação de testes de primalidade: fermat
def fermat(number, trials=20):
if number > 2:
# Repete o teste até o número de tentativas especificado.
for trial in range(trials):
# Gera um número aleatório entre 2 e number.
random_int = random.randint(2, number - 2 + 1)
@davidsonbrsilva
davidsonbrsilva / lazy.py
Created March 31, 2019 23:33
Implementação de testes de primalidade: lazy
# Lazy: verifica se um número é primo contando seus divisores.
def lazy(number):
divisions = 0
# Conta o número de divisores de number.
for index in range(1, number + 1):
if number % index == 0:
divisions += 1