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 Array | |
def sum | |
self.inject { |s, score| s + score } | |
end | |
end | |
class Student | |
def initialize( name, data ) | |
@name = name | |
@data = data |
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 Array | |
def sum | |
self.inject do |s, score| | |
s + score | |
end | |
end | |
end | |
class Student | |
def initialize(name) |
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 "test/unit" | |
require "pp" | |
require "./p101.rb" | |
class TC < Test::Unit::TestCase | |
def setup | |
# @eq = 1 # 1 is debug mode. Equation is un=n**3 | |
@eq = 0 | |
@o = P101.new( @eq ) | |
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 P101 | |
def initialize( eq = 0 ) | |
@n = 0 | |
@eq == eq | |
end | |
def main( m = 10 ) | |
(2..m).inject(1) do |sum, k| | |
sum + bop( polynomial( k )) | |
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
let グーチョキパー = 0 | |
input.onGesture(Gesture.Shake, () => { | |
グーチョキパー = Math.random(3) | |
music.beginMelody(music.builtInMelody(Melodies.BaDing), MelodyOptions.Once) | |
if (グーチョキパー == 0) { | |
basic.showLeds(` | |
. . . . . | |
. # . # . | |
# . # . # | |
# . . . # |
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 P84 | |
Num = 10000000 | |
def initialize | |
@board = | |
["GO","A1","CC1","A2","T1","R1","B1","CH1","B2","B3", | |
"JAIL","C1","U1","C2","C3","R2","D1","CC2","D2","D3", | |
"FP","E1","CH2","E2","E3","R3","F1","F2","U2","F3", | |
"G2J","G1","G2","CC3","G3","R4","CH3","H1","T2","H2"] | |
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
require "test/unit" | |
require "pp" | |
require "./p80.rb" | |
class TC < Test::Unit::TestCase | |
def test_div_num | |
o = P80.new | |
assert_equal( [3, 25], o.div_num( 325 ) ) # Divided to 2 digits. | |
assert_equal( [13, 25], o.div_num( 1325 ) ) | |
assert_equal( [9, 13, 25], o.div_num( 91325 ) ) |
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 P80 | |
def initialize | |
end | |
def main | |
square = Array.new(11) {|i| i * i} | |
square.delete_at(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
L = 1500000 | |
MaxM = Math::sqrt( L / 2.0 ).to_i + 1 | |
def pythagorean_nums | |
(2..MaxM).inject([]) do |result, m| | |
(1..m).each do |n| | |
next if m.gcd( n ) != 1 | |
next if (m - n) % 2 == 0 | |
l = (m*m - n*n) + (2*m*n) + (m*m + n*n) |
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 "test/unit" | |
require "pp" | |
require "./p74.rb" | |
class TC < Test::Unit::TestCase | |
def test_sum_factorial | |
o = P74.new | |
assert_equal( 1, o.sum_factorial(0) ) | |
assert_equal( 4*3*2, o.sum_factorial(4) ) | |
assert_equal( 4*3*2+2+6*5*4*3*2, o.sum_factorial(426) ) |
NewerOlder