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 Numeric | |
| def divisible_by? num | |
| self % num == 0 | |
| end | |
| def prime? | |
| not (2..self.sqrt.floor).any? {|i| self.divisible_by? i} | |
| end | |
| def sqrt |
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 Numeric | |
| def palindromic? | |
| to_s.reverse == to_s | |
| end | |
| end | |
| class Range | |
| def reverse | |
| ReverseRange.new last, first, exclude_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 Numeric | |
| def divisible_by? num | |
| self % num == 0 | |
| end | |
| end | |
| possible = increment = 20 * 19 | |
| test = (11..18).to_a.reverse | |
| loop do | |
| if test.all? {|d| possible.divisible_by? d} |
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 Numeric | |
| def squared | |
| self * self | |
| end | |
| end | |
| module Enumerable | |
| def sum &blk | |
| blk = proc {|x| x} unless block_given? | |
| inject(0) {|sum, element| sum + (blk[element] || 0)} |
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 Numeric | |
| def divisible_by? num | |
| self % num == 0 | |
| end | |
| def prime? | |
| not (2..self.sqrt.floor).any? {|i| self.divisible_by? i} | |
| end | |
| def sqrt |
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
| module Enumerable | |
| def prod | |
| inject(1) {|t, i| t * i.to_i} | |
| end | |
| end | |
| num = DATA.read.gsub /\s/, '' | |
| puts (0..num.length-5).collect {|start| num[start, 5].chars.prod}.max | |
| __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 Numeric | |
| def squared | |
| self * self | |
| end | |
| end | |
| (1..1000/3).each do |a| | |
| (a+1..1002-2*a).each do |b| | |
| c = 1000 - a - b | |
| if a + b > c && a.squared + b.squared == c.squared |
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
| mogrify -thumbnail 248x157^ -gravity center -extent 248x157 '*.jpg' |
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
| desc "Generate Heroku gems manifest from environment.rb" | |
| task 'heroku:gems:manifest' do | |
| manifest = nil | |
| IO.popen('-') do |io| | |
| if io | |
| manifest = io.read | |
| else | |
| system 'script/runner', %q{ | |
| out = Rails.configuration.gems.collect do |gem| | |
| gem.send(:install_command)[1..-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
| class Numeric | |
| def divisible_by? num | |
| self % num == 0 | |
| end | |
| def sqrt | |
| Math.sqrt self | |
| end | |
| def prime?(preprocessed=(2..self.sqrt.floor)) |