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 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) | |
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 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 |
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 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): |
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 snail(array): | |
| pass | |
| # Tests | |
| array = [[]] | |
| expected = [] | |
| test.assert_equals(snail(array), expected) |
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
| """ | |
| 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]] |
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
| # 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()) |
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 snail(array): | |
| return list(array[0]) + snail(zip(*array[1:])[::-1]) if array else [] | |
| # Tests | |
| array = [[]] | |
| expected = [] | |
| test.assert_equals(snail(array), expected) |
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 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) |
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
| """ | |
| 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 |
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 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) |