This file contains hidden or 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
#(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 = {} | |
#前の人がカットしたところから自分の分を求める |
This file contains hidden or 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' | |
class Lsystem | |
def initialize(width, height, title = "L-system") | |
@width = width | |
@height = height | |
@title = title | |
@procedure = "" | |
@command = {} | |
@rule = {} |
This file contains hidden or 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
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 { |
This file contains hidden or 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' | |
module LifeGame | |
class Field | |
MG = 4 | |
Small, Large = [70, 50], [85, 60] | |
def initialize | |
@width, @height = Small | |
@size = :small |
This file contains hidden or 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 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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| |