View blackjack.rb
deck = nil
shuffle = ->{
print "カードをシャッフルします\n\n"
deck = []
4.times do |i|
1.upto(13) {|j| deck << i * 100 + j}
end
deck.shuffle!
View linuxmint_backup.rb
require 'fileutils'
class String
def cut
/.+tomoki\/(.+)$/.match(self)[1]
end
end
def get_file_names(f)
dirs = Dir.glob("*")
View lifegame_for_RubyPico.rb
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
View calender.rb
#for RubyPico (mruby)
#mrubyには String#center がないので適当に実装
class String
def center(n)
i = (n - length).div(2)
" " * i + self + " " * (n - i - length)
end
end
View kaki-lifegame.rb
require 'gtk2'
module LifeGame
class Field
MG = 4
Small, Large = [70, 50], [85, 60]
def initialize
@width, @height = Small
@size = :small
View n_queen.go
package main
import "fmt"
const num = 15
var count = 0
func get_space(field []int) [num]int {
result := [num]int{}
l := len(field)
for i, queen := range field {
View lsystem.rb
require 'oekaki'
class Lsystem
def initialize(width, height, title = "L-system")
@width = width
@height = height
@title = title
@procedure = ""
@command = {}
@rule = {}
View q56a.rb
#(x, y)のケーキを切ってできる全ての (面積, 切った長さの合計) のペアを返す
#ただし面積はここでカットした人の総計
def cut(x, y)
x, y = y, x if x < y
return @memo[[x, y]] if @memo.has_key?([x, y])
return {1 => 1} if x == 2 and y == 1
result = {}
#前の人がカットしたところから自分の分を求める
View maze_never_turn_left.rb
class SolveMaze
open("maze_never_turn_left.txt") {|io| @@field = io.readlines}
@@field.map! {|f| " " + f.chomp + " "}
a = [" " * @@field[0].size]
@@field = a + @@field + a
class Position
def initialize(x, y, dir = nil, parent = nil)
@x, @y = x, y
@kind = get[y][x]
View lifegame.rb
require 'gtk2'
Width = 30
Height = 30
class Component
def initialize
f = Field.new(Width, Height)
f.generate(150)
if ARGV[0] == "-r"