Skip to content

Instantly share code, notes, and snippets.

View mvallebr's full-sized avatar

Marcelo Elias Del Valle mvallebr

View GitHub Profile
def find_it(seq):
unique = set(seq)
odd = (u for u in unique if seq.count(u) % 2 == 1)
return next(odd)
test.describe("Example")
test.assert_equals(find_it([20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5]), 5)
def maxSequence(arr):
max_sum = 0
current_sum = 0
for i in arr:
current_sum += i
current_sum = max(current_sum, i)
max_sum = max(current_sum, max_sum)
return max_sum
def sortear():
return [5,1,1,2]
def entrar():
return [int(x) for x in input().split()]
l_sorteio = sortear()
l_entrada = entrar()
def print_resultado(descricao, d_resultado):
def snail(array):
pass
# Tests
array = [[]]
expected = []
test.assert_equals(snail(array), expected)
"""
Description:
Snail Sort
Given an n x n array, return the array elements arranged from outermost elements to the middle element, traveling clockwise.
array = [[1,2,3],
[4,5,6],
[7,8,9]]
# Exemplo 1
n=int(input())
for i in range (1, n+1):
if i != n+1:
print(i, end=' ')
else:
print(i)
# Exemplo 2
n=int(input())
def snail(array):
return list(array[0]) + snail(zip(*array[1:])[::-1]) if array else []
# Tests
array = [[]]
expected = []
test.assert_equals(snail(array), expected)
def soma_parcial(lista, inicio, fim):
# soma_parcial(lista, inicio, inicio) = head
# soma_parcial(lista, inicio + 1, fim) = tail
return lista[inicio] if inicio == fim else soma_parcial(lista, inicio, inicio) + soma_parcial(lista, inicio + 1, fim)
@mvallebr
mvallebr / primes_in_numbers.py
Created May 22, 2017 23:29
primes in numbers
"""
Given a positive number n > 1 find the prime factor decomposition of n. The result will be a string with the following form :
"(p1**n1)(p2**n2)...(pk**nk)"
with the p(i) in increasing order and n(i) empty if n(i) is 1.
Example: n = 86240 should return "(2**5)(5)(7**2)(11)"
"""
from collections import defaultdict
from collections import defaultdict, Counter, deque
import math
def primeFac(n):
prime_list = deque()
pivot = 2
current = n
while current != 1 and pivot <= math.sqrt(n):
if current % pivot == 0:
prime_list.append(pivot)