Skip to content

Instantly share code, notes, and snippets.

View pandwoter's full-sized avatar
🙃
digging CS

Alexander Samchuk pandwoter

🙃
digging CS
  • Tbilisi, Georgia
View GitHub Profile
require 'concurrent'
require 'benchmark'
class Request
class << self
def make(num)
@body = Faraday.get("https://jsonplaceholder.typicode.com/todos/#{num}").body
self
end
@pandwoter
pandwoter / ants_problem.rb
Created October 13, 2020 12:36
ANTS PROBLEM
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') }
@pandwoter
pandwoter / top_k_word.rb
Created October 13, 2020 10:55
TOP K WORDS
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
@pandwoter
pandwoter / berber_shop.rb
Last active April 19, 2022 08:58
BARBER SHOP
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)
@pandwoter
pandwoter / merge_times.rb
Last active April 19, 2022 08:58
MERGE TIMES
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