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
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
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 '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
#(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
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] |
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' | |
Width = 30 | |
Height = 30 | |
class Component | |
def initialize | |
f = Field.new(Width, Height) | |
f.generate(150) | |
if ARGV[0] == "-r" |
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: 420, height: 420, title: "Turtle" do | |
draw {clear} | |
t = Oekaki::Turtle.new | |
t.color(0xffff, 0x45ff, 0) #orangered | |
t.move(-200, -200) | |
t.left(45) | |
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_relative "q50disp" | |
W, H = 6, 5 | |
def putout | |
return if @memo.include?([@yoko, @tate]) | |
@memo << (a = Marshal.load(Marshal.dump([@yoko, @tate]))) | |
Disp.show(*a) | |
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 'oekaki' | |
W, H = 260, 220 | |
L = 40 | |
yoko = [[1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0], [0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 1], [1, 0, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0]] | |
tate = [[0, 0, 0, 0, 1], [0, 0, 1, 1, 0], [1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 1, 1, 0, 0], [0, 1, 1, 0, 0], [0, 0, 0, 1, 1]] | |
Oekaki.app width: W, height: H do | |
draw do |