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 | |
| VERSION = 1 | |
| NUMERALS = { | |
| 1000 => 'M', | |
| 900 => 'CM', | |
| 500 => 'D', | |
| 400 => 'CD', | |
| 100 => 'C', | |
| 90 => 'XC', | |
| 50 => 'L', |
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 Complement | |
| H = { | |
| 'G' => 'C', | |
| 'C' => 'G', | |
| 'T' => 'A', | |
| 'A' => 'U' | |
| } | |
| VERSION = 3 | |
| def self.of_dna(dna) | |
| a = dna.split('') |
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 Raindrops | |
| VERSION = 1 | |
| def self.convert(num) | |
| dup = num | |
| a = [] | |
| while num > 1 | |
| for i in (2..num) | |
| if num%i == 0 | |
| num = num / i | |
| a << i |
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 Pangram | |
| VERSION = 1 | |
| def self.is_pangram?(str) | |
| ref = ('a'..'z').to_a | |
| str.downcase.split('').select{|i| ref.include?(i)}.uniq.sort == ref | |
| end | |
| 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 Hamming | |
| VERSION = 1 | |
| def self.compute(x,y) | |
| distance = 0 | |
| if x.length == y.length | |
| x.split('').each_with_index do |elem,i| | |
| distance = distance + 1 unless y[i] == elem | |
| end | |
| return distance | |
| else |
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 Gigasecond | |
| GS = 10**9 | |
| VERSION = 1 | |
| def self.from(date) | |
| return date + GS | |
| end | |
| 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 Squares | |
| attr_accessor :number | |
| VERSION = 2 | |
| def initialize(num) | |
| self.number = num | |
| end | |
| def square_of_sum | |
| self.number > 0 ? ((1..self.number).to_a.inject(:+))**2 : 0 | |
| end |