Skip to content

Instantly share code, notes, and snippets.

View vincentchin's full-sized avatar

Vincent Chin vincentchin

  • New York
View GitHub Profile
class Image
def initialize(array)
@array = array
@new_array = @array.map {|e| Array.new(e.size) }
end
def blur
@array.each_with_index do |row,x|
row.each_with_index do |cell,y|
last_x_pixel = row.size - 1
class Image
attr_accessor :array
def initialize(array)
@array = array
@cells = []
@new_array = @array.map {|e| Array.new(e.size) }
end
def all_array_indexes
@vincentchin
vincentchin / linked_list_stack.rb
Created September 3, 2015 22:21
Reverse a linked list by implementing a stack data structure.
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)
@vincentchin
vincentchin / linked_list_mutation.rb
Created September 4, 2015 15:40
Reverse a linked list using mutation
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)
@vincentchin
vincentchin / dfs.rb
Last active September 17, 2015 19:16
# In the above example it will check to see if the payload is 11 in the following order: 2, 7, 6, 5 when
# it gets to 5 and 5 has no children, it will return to the 6 and go to any children 6 has. 6 has a
# remaining child, which is 11 so that node is checked and since that value is the correct value it
# will be returned and searching will stop.
class Tree
attr_accessor :payload, :children
def initialize(payload, children)
@payload = payload
require 'minitest/autorun'
module Luhn
def self.is_valid?(number)
digits = number.to_s.split("")
digits.map! {|x| x.to_i }
ary = Array.new
digits.each_with_index do |value, index|
if index.even?