Skip to content

Instantly share code, notes, and snippets.

View dbhalling's full-sized avatar

Dale B Halling dbhalling

View GitHub Profile
@dbhalling
dbhalling / gist:a6da1e3553c4a3f7f5011ed2969894bb
Created August 26, 2018 05:57
#codality35 CommonPrimeDivisors
#codality35 CommonPrimeDivisors
require 'prime'
a = [15, 10, 3, 2]
b = [75, 30, 5, 8]
def solution(a, b)
@dbhalling
dbhalling / gist:15a04d589a5ecc848cd75a4ca83fb941
Created August 25, 2018 08:02
Codility34 ChocolatesByNumbers
#Codility34 ChocolatesByNumbers
n = 10
m = 4
def solution(n, m)
step= 0
stepArray = [0]
@dbhalling
dbhalling / gist:61776b49658485e75df90aa2d9671da4
Last active August 24, 2018 09:54
Codality - Determine maximum bitgap
#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
@dbhalling
dbhalling / gist:9c97c618b4510c4e195ab9e46bb9e8d0
Last active August 24, 2018 09:52
Codility Odd Occurrences in an Array
#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
@dbhalling
dbhalling / gist:67b20f755f24e6efb42c22fe085f0d0d
Last active August 24, 2018 09:52
Codility Array Rotation
#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
@dbhalling
dbhalling / gist:2ac3eeb254ee2140c2b97c5043754bdf
Last active August 24, 2018 09:51
codility PermMissingElem
#codility PermMissingElem
a = [2, 3, 1, 5]
def solution(a)
b = []
b = a.sort
count = b.count
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
@dbhalling
dbhalling / gist:d1079b291adf0777072d9a62699027fc
Last active August 24, 2018 09:50
codility6 TapeEquilibrium
#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
@dbhalling
dbhalling / gist:3ebe01f094ef133042db1e60f9d6ce4e
Last active August 24, 2018 09:49
codility4.1 PermCheck
#codility4.1 PermCheck
#a = [4, 1, 3]
a = [4, 3, 2, 1]
def solution(a)
answer = 0
count = a.count
b = []
@dbhalling
dbhalling / gist:6fffa8dd079314779fbc6310aff7b5a7
Last active August 24, 2018 09:49
codility8 FrogRiverOne
#codility8 FrogRiverOne
a = [1, 3, 1, 4, 2, 3, 5, 4]
x = 5
def solution(x, a)
time = []
sort = a.sort.uniq!
i = 0