Skip to content

Instantly share code, notes, and snippets.

View vk26's full-sized avatar

Dmitry Belyavtsev vk26

  • Saint Petersburg
View GitHub Profile
def valid_brackets?(brackets_string)
stack = []
matcher = { ')' => '(', '}' => '{' }
brackets_string.chars.each do |el|
if matcher.values.include? el
stack.push el
elsif stack.last == matcher[el]
stack.pop
else
return false
@vk26
vk26 / search_missing_values.rb
Last active September 15, 2015 14:23
Поиск 2 пропущенных элементов отсортированного массива. Двумя способами: через бинарный поиск и через побитовые операции.
require 'byebug'
require 'wrong/assert'
require "benchmark/ips"
include Wrong::Assert
module Search
def get_bit(num, bit = 1)
unless num & bit == 0
return bit
else