This file contains 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 P74 | |
def initialize | |
@max = 1000000 | |
@factorials = make_factorial | |
@sum_factorials = [] | |
@num_loops = [] | |
end | |
def main |
This file contains 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
def body( d ) | |
d.downto(2).inject( Rational(0,1) ) do |fin, denominator| | |
value = Rational( 3 * denominator / 7, denominator ) | |
value > fin && value != Rational( 3, 7 ) ? value : fin | |
end | |
end | |
p body( 1000000 ).numerator |
This file contains 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 P69 | |
MAXN = 1000000 | |
def initialize(n = MAXN) | |
@n = n | |
end | |
def main | |
phis = phis( @n ) | |
phis.index( max_phi( phis ) ) + 1 |
This file contains 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 "pp" | |
class Array | |
def includes?( content ) | |
self.each.any? do |row| | |
row.include?( content ) | |
end | |
end | |
end |
This file contains 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 P59 | |
def initialize | |
@w_the = "the ".split("").map(&:ord) | |
end | |
def main | |
encorded_words = read_file( "cipher1.txt" ) | |
("a".ord.."z".ord).each do |key0| | |
("a".ord.."z".ord).each do |key1| |
This file contains 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 'wiringpi2' | |
$a_pin = 1 #18 | |
$b_pin = 4 #23 | |
$led_pin = 0 #17 | |
def discharge | |
io = WiringPi::GPIO.new do |gpio| | |
gpio.pin_mode($a_pin, WiringPi::INPUT) | |
gpio.pin_mode($b_pin, WiringPi::OUTPUT) |
This file contains 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
include Math | |
class Integer | |
def prime? | |
return false if self == 0 || self == 1 | |
(2..sqrt(self).to_i).all? { |i| self % i != 0 } | |
end | |
end | |
def prime_cornars( h ) |
This file contains 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
def root2_series | |
(1..1000).inject([[3,2]]) do |result, n| | |
result << [result.last[0] + 2 * result.last[1], result.last[0] + result.last[1]] | |
end | |
end | |
def bigger_numerators | |
root2_series.select do |term| | |
term[0].to_s.size > term[1].to_s.size | |
end |
This file contains 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
def root2_series | |
(1..1000).inject( [3/2r] ) do |result, i| | |
result << 1 + 1 / (result.last + 1) | |
end | |
end | |
def bigger_numerators | |
root2_series.select do |term| | |
term.numerator.to_s.size > term.denominator.to_s.size | |
end |
This file contains 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 P55 | |
def main | |
(1..9999).select { |i| i.lychrel? }.size | |
end | |
end | |
class Integer | |
def reverse | |
self.to_s.reverse.to_i | |
end |