Skip to content

Instantly share code, notes, and snippets.

View gbazilio's full-sized avatar

Guilherme Bazilio gbazilio

View GitHub Profile
@gbazilio
gbazilio / remove_dot_.sh
Created June 3, 2015 19:14
Recursively removing files with ._ prefix. These files are automatically created by Mac OS.
find . -name "._*" -exec rm -rf {} \;
@gbazilio
gbazilio / binary-gap.py
Last active January 16, 2017 23:29
Codility - Binary Gap
def solution(N):
if N < 0: return 0
binary_string = bin(N)[2:]
max_gap_count = current_gap_count = 0
for index in range(len(binary_string)):
if binary_string[index] == "0":
current_gap_count += 1
else:
@gbazilio
gbazilio / cyclic-rotation.py
Created January 4, 2017 17:31
Codility - Cyclic Rotation
def solution(A, K):
A_length = len(A)
new_A_array = [0] * A_length
for index in range(A_length):
shift_index = (index+K) % A_length
new_A_array[shift_index] = A[index]
return new_A_array
@gbazilio
gbazilio / odd-occurrences.py
Last active January 17, 2017 20:43
Codility - Odd occurrences
def solution(A):
A = sorted(A)
for index in range(0, len(A), 2):
next_index = index+1
if next_index >= len(A) or A[index] != A[index+1]:
return A[index]
@gbazilio
gbazilio / missing-element.py
Created January 8, 2017 14:28
Codility - Missing element
def solution(A):
A_length = len(A)
array_sum = sum(A)
complete_sequence_sum = (A_length * (A_length + 1) / 2) + (A_length + 1)
return complete_sequence_sum - array_sum
@gbazilio
gbazilio / frog-jump.py
Created January 8, 2017 17:15
Codility - Frog jumps
def solution(X, Y, D):
return int(math.ceil((Y - X) / float(D)))
@gbazilio
gbazilio / tape-equilibrium.py
Created January 8, 2017 22:25
Codility - Tape equilibirum
def solution(A):
sum_of_part_two = sum(A)
min_difference = None
sum_of_part_one = 0
for i in xrange(1, len(A)):
sum_of_part_one += A[i-1]
sum_of_part_two -= A[i-1]
difference = abs(sum_of_part_one - sum_of_part_two)
if (min_difference == None):
@gbazilio
gbazilio / permutation.py
Created January 9, 2017 23:46
Codility - Permutation
def solution(A):
n = len(A)
A_sum = sum(set(A))
ideal_sum = n*(n+1)/2
return 1 if A_sum == ideal_sum else 0
@gbazilio
gbazilio / missing-integer.py
Created January 11, 2017 00:23
Codility - Missing integer
def solution(A):
count_length = len(A)
count_array = [0] * (count_length + 1)
for value in A:
if value > 0 and value <= count_length:
count_array[value-1] += 1
for index in xrange(len(count_array)):
if count_array[index] == 0:
@gbazilio
gbazilio / frog-jump-leaves.py
Created January 12, 2017 21:39
Codiligty - Frog jump leaves
def solution(X, A):
count_array = [0] * (X)
leaves = 0
for index in xrange(len(A)):
if count_array[A[index] - 1] == 0:
count_array[A[index] - 1] = 1
leaves += 1
if leaves == X:
return index
return -1