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
# Представь, что ты работаешь в букмекерской конторе программистом и тебя попросили написать функцию, | |
# которая на вход принимает два футбольных счета - тот который загадал клиент когда делал ставку | |
# и реальный результат футбольного матча (то как сыграли команды на самом деле). На выходе нужно получить: | |
# 2 - если клиент полностью угадал счет | |
# 1 - если клиент угадал какая команда победит или угадал ничью | |
# 0 - если не угадал ничего | |
# | |
# счет кодируется строкой вида "1:0" | |
# |
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
# usage BfsTraverse.call(order) { |order| order.related_orders } | |
class BfsTraverse | |
def call(element, &adjacents_proc) | |
node = Node.new(element, &adjacents_proc) | |
BreadthFirstSearch.new(node).to_a.map(&:element) | |
end | |
class Node | |
attr_reader :element | |
def initialize(element, &adjacents_proc) |
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 'set' | |
# Purpose of this class - to build connected undirected graph | |
# and effectively find all possible paths between vertices | |
# relations between docs in graph described below. | |
# Algorithm to build graph: bidirect breadth first search inspired by https://github.com/jwngr/sdow | |
# | |
# Example: | |
# doc1: | |
# id: 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
#!/usr/bin/env ruby | |
# Simple script, sorting tests by duration to analyze slow tests. | |
# Usage: | |
# chmod +x sort_tests.sh | |
# rspec -f d spec/ | sort_tests.sh | |
data = [] | |
prev_time = nil |