Skip to content

Instantly share code, notes, and snippets.

View mame-n's full-sized avatar

Shouichi Nakauchi mame-n

View GitHub Profile
class P74
def initialize
@max = 1000000
@factorials = make_factorial
@sum_factorials = []
@num_loops = []
end
def main
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
class P69
MAXN = 1000000
def initialize(n = MAXN)
@n = n
end
def main
phis = phis( @n )
phis.index( max_phi( phis ) ) + 1
require "pp"
class Array
def includes?( content )
self.each.any? do |row|
row.include?( content )
end
end
end
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|
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)
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 )
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
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
class P55
def main
(1..9999).select { |i| i.lychrel? }.size
end
end
class Integer
def reverse
self.to_s.reverse.to_i
end