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
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) |
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
# 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 |
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
#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 |
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
<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"})) |
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 |
OlderNewer