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 ProblemA | |
def initialize | |
@input = [[[1,nil]], | |
[[5,nil], | |
[0,0], [0,1], [0,2], [0,3]], | |
[[12,nil], | |
[0,0], [1,0], [2,0], [3,1], [4,1], [5,1], [6,2], [7,2], [8,2], [9,3], [10,3]], | |
[[10, nil], | |
[0,2], [1,2], [2,2], [3,2], [2,1], [5,1], [6,1], [7,1], [8,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
Max = 10**6 # 1000000 | |
res = [] | |
res_odd = [] | |
res[1] = 1 | |
res_odd[1] = 1 | |
t = 2 | |
tetrahedron = t * (t+1) * (t+2) / 6 |
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
module TNum | |
Tnull = [ | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], | |
[0,0,0,0,0,0], |
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 Timer | |
public | |
def initialize(interval, &callback_block) | |
@loop_enable = false | |
@interval = interval | |
@callback_block = callback_block | |
end | |
def start() | |
@loop_enable = true | |
loop_start() |
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 'minecraft-pi-ruby' | |
require './num_block' | |
require './timer' | |
class Timer_ctrl | |
def initialize | |
@num_mcpi = NumericalMCPI.new | |
@timer = Timer.new(1) do | |
Thread.new() do |
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 |
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
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
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
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) |
OlderNewer