Skip to content

Instantly share code, notes, and snippets.

View stevenbarragan's full-sized avatar

Steven Barragán Naranjo stevenbarragan

View GitHub Profile
# https://www.codewars.com/kata/snail
def snail(matriz)
result = []
step = 0
while matriz.size > 0
step = 0 if step > 3
case step
when 0
result += matriz.shift
class Throttler
def initialize(time_limit, &block)
@block = block
@created_at = Time.now
@time_limit = time_limit
@block.call()
end
def call
Verifying my Blockstack ID is secured with the address 13z2CgHWH2xyGaQWkxghJqASZgkmnux3wX https://explorer.blockstack.org/address/13z2CgHWH2xyGaQWkxghJqASZgkmnux3wX
def josephus(input, k)
a = []
i = 0
while items.size > 0
i += k - 1
i = i % items.size
a << items.slice!(i)
end
class Base
attr_reader :value
def initialize(value)
@value = value
end
end
class Number < Base
def plus

Welcome to StackTest!

##Quotes api

###Model Quote * text type string

Task

  • Build a RESTFUL API for Quote model
@stevenbarragan
stevenbarragan / tape_equilibrium.rb
Created February 19, 2014 02:19
Tape equilibrium (Codility exercise)
def solution(a)
minor = 1/0.0
left = 0
right = a.reduce(:+)
a[0..-2].each do |x|
left += x
right -= x
@stevenbarragan
stevenbarragan / insersection.rb
Last active January 3, 2016 12:19
Emulate array insertion but allowing repeated numbers
def intersection(a, b)
hash = {}
c = []
a.each do |x|
hash[x] ? hash[x] += 1 : hash[x] = 1
end
b.each do |x|
c << x && hash[x] -= 1 if hash[x] && hash[x] > 0
@stevenbarragan
stevenbarragan / diagonal.rb
Last active January 3, 2016 08:09
From a n x n array print out all the diagonals
def diagonal(a)
x = y = 0
out = []
limit = a.size - 1
(0..limit * 2).each do
out << down(x,y,a)
x += 1 if y == limit
y += 1 if y < limit
end
out