Skip to content

Instantly share code, notes, and snippets.

# test for Flatstack
# https://github.com/fs/test-tasks/tree/master/ruby
# Дана последовательность:
# 1
# 11
# 21
# 1211
# 111221
# 312211
# Нужно чтобы ваша программа могла продолжить данную последовательность. Можете в реализации использовать любые библиотеки.
@sofakingworld
sofakingworld / Bracket balance function
Last active August 25, 2016 09:11
Bracket balance function
def brackets_balanced?(s)
brackets = [['(',')'],['[',']'],['{','}']]
flatten_brackets = brackets.flatten
close_brackets = brackets.map{|e| e[1]}
stack = ''
for i in 0..s.size do
stack += s[i] if flatten_brackets.include?(s[i])
stack = stack[0,stack.size-2] if brackets.include? [stack[stack.size-2,1],stack[stack.size-1,1]]
return false if close_brackets.include? stack[stack.size-1,1]
end
@sofakingworld
sofakingworld / Formulation of the problem
Last active August 22, 2016 19:47
TSQL (MS SQL) Polygon issues :)
Is a table containing identifiers and the vertex coordinates of figures.
P (Polygon_id int, point_id int, x float, y float)
Points are listed sequentially in a clockwise or counter- clockwise
1. It is necessary to write a function that returns the area of a selected polygon
2. It is necessary to write a function that returns the perimeter of the selected polygon
3. Check whether the point is on the specified coordinates inside the polygon
@sofakingworld
sofakingworld / gist:c47dd6a022934826f7c62769b814039b
Created August 22, 2016 18:15
TSQL (MS SQL) Query result as string
select Value+CHAR(32) from Table
for xml path('')