This file contains 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
#codality35 CommonPrimeDivisors | |
require 'prime' | |
a = [15, 10, 3, 2] | |
b = [75, 30, 5, 8] | |
def solution(a, b) | |
This file contains 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
#Codility34 ChocolatesByNumbers | |
n = 10 | |
m = 4 | |
def solution(n, m) | |
step= 0 | |
stepArray = [0] |
This file contains 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
#codility1 | |
puts "Enter and integer" | |
n = gets().chomp.to_i | |
def bitgap(n) | |
b = n.to_s(2) | |
bits = n.bit_length | |
leastbit = b[bits - 1].to_i |
This file contains 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
#codility2 Odd Occurrences in an Array | |
#a = [9, 3, 9, 3, 9, 7, 9] | |
a = [1, 3, 1, 3, 4, 4, 14] | |
def oddone(a) | |
a.sort! | |
i = 0 | |
while |
This file contains 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
#Codility array rotation | |
a = [3, 8, 9, 7, 6] | |
puts "Enter rotation number" | |
k = gets.chomp.to_i | |
# k is the number of indices to shift the array |
This file contains 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
#codility PermMissingElem | |
a = [2, 3, 1, 5] | |
def solution(a) | |
b = [] | |
b = a.sort | |
count = b.count |
This file contains 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
codility 5 frogJump | |
#x is the starting position of the frog | |
x = 10 | |
#y is the ending position of the frog | |
y = 111 | |
#d is the number of positions the frog can jump | |
d = 30 |
This file contains 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
#codility6 TapeEquilibrium | |
a = [3, 1, 2, 4, 3] | |
#a = [1, 2, 3] | |
puts "The array is #{a}" | |
def solution(a) | |
count = a.count | |
sum = 0 |
This file contains 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
#codility4.1 PermCheck | |
#a = [4, 1, 3] | |
a = [4, 3, 2, 1] | |
def solution(a) | |
answer = 0 | |
count = a.count | |
b = [] |
This file contains 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
#codility8 FrogRiverOne | |
a = [1, 3, 1, 4, 2, 3, 5, 4] | |
x = 5 | |
def solution(x, a) | |
time = [] | |
sort = a.sort.uniq! | |
i = 0 |
NewerOlder