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
require 'concurrent' | |
require 'benchmark' | |
class Request | |
class << self | |
def make(num) | |
@body = Faraday.get("https://jsonplaceholder.typicode.com/todos/#{num}").body | |
self | |
end |
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
class Ant | |
DIRECTIONS = [[1,0], [0,1], [-1,0], [0,-1]] # [0]:right, [1]:bottom, [2]:left, [3]:top | |
def in_border? | |
(0 <= @position_x && @position_x < @size_x) && (0 <= @position_y && @position_y < @size_y) | |
end | |
def initialize(size, turns, middle = size/2) | |
@matrix = Array.new(size) { Array.new(size, 'W') } |
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
def top_k_words(str, n) | |
return [] if n < 0 | |
str = str.downcase.scan(/[\w']+/) | |
occurances = Hash.new | |
str.each do |word| | |
if occurances[word] | |
occurances[word] += 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
def calculate_time(customers_in_line, barbers_speed) | |
customers_queue = Queue.new | |
customers_in_line.times { |i| customers_queue << i } | |
required_time = 0 | |
barbers_progress = {} | |
barbers_speed.sort.each.with_index do |speed, idx| | |
customers_queue.pop(true) | |
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
require 'date' | |
# task input | |
input = [['10:00', '10:20'], | |
['10:40', '11:00'], | |
['10:50', '12:00'], | |
['12:00', '13:00'], | |
['10:00', '10:20']] | |
class TimeConverter |