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 characters
require 'pry' | |
require 'test/unit' | |
class Array | |
def bubble_sort | |
ary = self.dup | |
(size - 1).downto(0) do |i| | |
(0...i).each do |j| | |
ary[j], ary[j + 1] = ary[j + 1], ary[j] if ary[j] > ary[j + 1] |
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 characters
require 'pry' | |
require 'test/unit' | |
class Array | |
def bubble_sort | |
ary = self.dup | |
ary.size.times do | |
ary = ary.inject([]) do |result, num| | |
if result == [] |
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 characters
require 'test/unit' | |
class Array | |
def bubble_sort | |
(0...(size)).each do |i| | |
((i + 1)...(size)).each do |j| | |
self[i], self[j] = self[j], self[i] if self[i] > self[j] | |
end | |
end | |
self |
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 characters
class Array | |
def flat? | |
self.each do |n| | |
return false unless first == n | |
end | |
true | |
end | |
end | |
def lcm(a, b) |
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 characters
<?php | |
class Compose | |
{ | |
public static function _() | |
{ | |
$callables = func_get_args(); | |
return array_reduce($callables, function ($a, $b) { | |
if ($a === null) { |
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 characters
class Fixnum | |
def prime? | |
return false if self <= 1 | |
(2..(Math::sqrt(self))).each do |n| | |
return false if self % n == 0 | |
end | |
true | |
end |
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 characters
class Fib | |
def at(n) | |
raise "invalid index" unless n > 0 | |
if n == 1 | |
0 | |
elsif n == 2 | |
1 | |
else | |
at(n - 1) + at(n - 2) | |
end |
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 characters
require 'pry' | |
class Block | |
(class << self; self; end;).class_eval do | |
def output(input) | |
ary = input.each_line.inject([]) { |result, line| result << line.chomp! } | |
result = [] | |
loop do | |
break if ary.first == '0 0' | |
result << judge(ary) |
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 characters
Pry.commands.alias_command 'c', 'continue' | |
Pry.commands.alias_command 's', 'step' | |
Pry.commands.alias_command 'n', 'next' |
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 characters
class NumberOfIsland | |
(class << self; self; end;).class_eval do | |
def output(input) | |
input.split("\n\n").inject([]) { |result, line| result << run(line) }.join("\n") | |
end | |
def run(input, x = 0, y = 0, checked = [], count = 0) | |
ary = convert_to_array(input) | |
ary.size.times do | |
row = [] |