Last active
December 18, 2015 20:59
-
-
Save vanhalt/5844145 to your computer and use it in GitHub Desktop.
Revisions
-
vanhalt revised this gist
Aug 29, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ [*1..100].each do |number| text = "" text << "fizz " if number % 3 == 0 text << "buzz " if number % 5 == 0 unless text.empty? puts text -
vanhalt renamed this gist
Aug 29, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ [*1..100].each do |number| text = "" text << "fist " if number % 3 == 0 text << "buzz " if number % 5 == 0 unless text.empty? puts text else -
vanhalt revised this gist
Jul 23, 2013 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ [*1..100].each do |number| text = "" text << "fist " if number % 3 == 0 text << "boost " if number % 5 == 0 unless text.empty? puts text else puts number end end -
vanhalt revised this gist
Jun 23, 2013 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class IndexSort def self.sort(ary, ascend=true) ary_ = [] ary.each do |num| ary_[num] = num end ary_ = ary_.select { |value| !value.nil? } ascend ? ary_ : ary_.reverse end end -
vanhalt revised this gist
Jun 23, 2013 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -29,16 +29,16 @@ def contents @hsh.values.collect(&:content) end def deleted?(item) item.prev.nil? && item.next.nil? end def last @hsh.each_pair.select { |index, item | !deleted?(item) && item.next.nil? }.first.last.content end def first @hsh.each_pair.select { |index, item | !deleted?(item) && item.prev.nil? }.first.last.content end private -
vanhalt revised this gist
Jun 23, 2013 . 1 changed file with 15 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,10 +7,14 @@ def initialize(content) @hsh[0].content = content end def add(element) if element.instance_of? LinkedList element.contents.each do |value| add_content value end else add_content element end end def delete(index) @@ -36,4 +40,11 @@ def last def first @hsh.each_pair.select { |index, item | !unlinked?(item) && item.prev.nil? }.first.last.content end private def add_content(content) index = @hsh.length @hsh[index-1].next = index if index > 1 @hsh[index] = ITEM.new(index-1, nil, content) end end -
vanhalt created this gist
Jun 23, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ class LinkedList ITEM = Struct.new :prev, :next, :content def initialize(content) @hsh = {} @hsh[0] = ITEM.new(nil, nil, content) @hsh[0].content = content end def add(content) index = @hsh.length @hsh[index-1].next = index if index > 1 @hsh[index] = ITEM.new(index-1, nil, content) end def delete(index) item = @hsh[index] @hsh[item.prev].next = item.next @hsh[item.next].prev = item.prev item.prev = nil item.next = nil end def contents @hsh.values.collect(&:content) end def unlinked?(item) item.prev.nil? && item.next.nil? end def last @hsh.each_pair.select { |index, item | !unlinked?(item) && item.next.nil? }.first.last.content end def first @hsh.each_pair.select { |index, item | !unlinked?(item) && item.prev.nil? }.first.last.content end end