Skip to content

Instantly share code, notes, and snippets.

View gagaception's full-sized avatar

Aziz Sharipov gagaception

  • Berlin
  • 10:23 (UTC +02:00)
View GitHub Profile
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
def print_values(list_node)
class Image
attr_accessor :data
def initialize (data)
@data = data
end
def image_blur
all_done = false
@data.each_with_index do |row, row_index|
row.each_with_index do |value, column_index|
@gagaception
gagaception / challenge#1.rb
Last active October 13, 2015 14:03
image_blur
class Image
attr_accessor :data
def initialize (data)
@data = data
end
def output
@data.each do |sub|
sub.each do |cell|
print cell
@gagaception
gagaception / binary_tree.rb
Last active October 22, 2015 08:44
binary_tree
class BinaryTree
attr_accessor :value, :left, :right
def initialize (value)
@value = value
end
end
class SortBinaryTree
@gagaception
gagaception / tr_tree.rb
Last active October 22, 2015 08:46
tr_tree
class Tree
attr_accessor :value, :children
def initialize(value, children = [])
@value = value
@children = children
end
end
def BFS(data, target)
queue = [data]
class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
def print_values(list_node)
def recursive_fib(n)
if n <= 1
return n
else
result = recursive_fib(n-2) + recursive_fib(n-1)
end
end
def itterative_fib(n)
fib = [0, 1]
require 'minitest/autorun'
require_relative 'binary_tree'
class BinaryTreeTest < Minitest::Test
def test_data_is_saved
assert_equal 7, BinaryTree.new(7).value
end
def test_inserting_left
seven = SortBinaryTree.new(7)
module LongestSubstring
def self.find(first, second)
return nil if first.nil? || second.nil?
return nil if first != second
x, xs, y, ys = first[0..0], first[1..-1], second[0..0], second[1..-1]
if x == y
x + self.find(xs, ys)
else
[self.find(first, ys), self.find(xs, second)].max_by {|x| x.size}
def lcs(first, second)
return nil if first.nil? || second.nil?
x, xs, y, ys = first[0..0], first[1..-1], second[0..0], second[1..-1]
if x == y
x + lcs(xs, ys)
else
[lcs(first, ys), lcs(xs, second)].max_by {|x| x.size}
end
end