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
# Gem 'rubysdl' に付属しているサンプルを modify したものです | |
require 'sdl' | |
class Object | |
def deep_clone | |
Marshal::load(Marshal.dump(self)) | |
end | |
end | |
class Pattern |
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
parameters = [:factorial] | |
args = [[:lambda, [:n], [:if, [:<, :n, 1], 1, [:*, :n, [:factorial, [:-, :n, 1]]]]]] | |
body = [:factorial, 4] | |
ext_env = [{:factorial=>:dummy}, | |
{:+ =>[:prim, #<Proc:0x000055a6a4665a80@μSchemeR1.rb:24 (lambda)>], | |
:- =>[:prim, #<Proc:0x000055a6a4665a30@μSchemeR1.rb:25 (lambda)>], | |
:* =>[:prim, #<Proc:0x000055a6a46659e0@μSchemeR1.rb:26 (lambda)>], | |
:/ =>[:prim, #<Proc:0x000055a6a4665990@μSchemeR1.rb:27 (lambda)>], | |
:> =>[:prim, #<Proc:0x000055a6a4665940@μSchemeR1.rb:28 (lambda)>], |
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 'gtk2' | |
class GUI < Gtk::Window | |
Meth = [:wanwan, :nya] | |
def initialize(&bk) | |
super("GUI") | |
set_width_request(200) | |
box = Gtk::VBox.new |
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 CubeMaze | |
class Wall | |
def initialize(x, y, h, ob) | |
@wall = Array.new(h + 1) {Array.new(y) {Array.new(x, 1)}} | |
@x, @y = x, y | |
@cube = ob | |
end | |
attr_reader :wall | |
def break(num, 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 'oekaki' | |
Oekaki.app width: 500, height: 500 do | |
draw { clear(color(0x1694, 0x3447, 0x8d60)) } | |
t = Oekaki::Turtle.new | |
t.color(0xfe5f, 0xaa9a, 0x212a) | |
ln = 10 | |
e = Enumerator.new do |y| |
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 prime_table(n) | |
return [] if n < 2 | |
return [2] if n == 2 | |
table = [2, 3] | |
i, step = 5, 2 | |
while i <= n | |
guard = Math.sqrt(i).to_i | |
table.each do |prime| | |
break if (i % prime).zero? | |
if prime > guard |
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
deck = nil #カードの山 | |
shuffle = lambda do | |
print "カードをシャッフルします\n\n" | |
deck = 4.times.flat_map {|i| (1..13).map {|j| i * 100 + j} }.shuffle | |
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 'fileutils' | |
class String | |
def cut | |
/.+tomoki\/(.+)$/.match(self)[1] | |
end | |
end | |
def get_file_names(f) | |
dirs = Dir.glob("*") |
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 LifeGame | |
W, H = 124, 38 | |
def initialize(n) | |
@field = new_field | |
scatter(n) | |
end | |
def set_cell(x, y) | |
@field[y + 1][x + 1] = 1 | |
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
#for RubyPico (mruby) | |
#mrubyには String#center がないので適当に実装 | |
class String | |
def center(n) | |
i = (n - length).div(2) | |
" " * i + self + " " * (n - i - length) | |
end | |
end |