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: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:b1d400be90340e71142d889781d2b62c
Created September 26, 2017 17:15
Split temperature sequence
t = [5, -2, 3, 8, 6]
#t = [-5, -5, -5, -42, 6, 12]
def winter(t)
length = t.count
lengthsummer = length/2
lengthwinter = length - lengthsummer
twinter = t.take(lengthwinter)
@dbhalling
dbhalling / gist:1a7c058c92cfb3586f6929d4c327ca62
Created September 26, 2017 17:54
Infinite Chessboard - Minimum number of moves by rook to final position
# chess game Rook on an infinte Cheesboard. Find the minium number of steps to the final position
finalposition = [5,-77]
def rook(finalposition)
start = [0,0]
finalposition[0] = finalposition[0].abs
finalposition[1] = finalposition[1].abs
#frog jump
#array a is a set of stones in a river and the value is when stone is above the waterline in time
#d is how many stones the frog can jump
#a = [1,-1,0,2,3,5]
a = [1, 2, 3]
#d = 3
d = 1
@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:39b9d15c3990a2ea48f03607846d3c90
Created September 27, 2017 21:04
Bitcoin Bitfinex ticker
<html>
<div id="btc">
</div>
<script>
var ws = new WebSocket("wss://api.bitfinex.com/ws")
ws.onopen = function(){
ws.send(JSON.stringify({"event":"subscribe", "channel":"ticker", "pair":"BTCUSD"}))
@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