Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / kaki-lifegame.rb
Last active May 8, 2022 10:26
エディタ付きライフゲーム(Ruby)
require 'gtk2'
module LifeGame
class Field
MG = 4
Small, Large = [70, 50], [85, 60]
def initialize
@width, @height = Small
@size = :small
@obelisk68
obelisk68 / n_queen.go
Last active April 17, 2018 19:57
15 queen
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 {
@obelisk68
obelisk68 / lsystem.rb
Last active March 22, 2018 05:00
L-system の実装
require 'oekaki'
class Lsystem
def initialize(width, height, title = "L-system")
@width = width
@height = height
@title = title
@procedure = ""
@command = {}
@rule = {}
@obelisk68
obelisk68 / q56a.rb
Last active April 18, 2018 02:37
公平に分けられたケーキ
#(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 = {}
#前の人がカットしたところから自分の分を求める
@obelisk68
obelisk68 / maze_never_turn_left.rb
Last active February 21, 2018 00:33
絶対左折禁止の迷路を解く
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]
@obelisk68
obelisk68 / lifegame.rb
Created February 19, 2018 13:40
Ruby でライフゲーム(with GTK+)
require 'gtk2'
Width = 30
Height = 30
class Component
def initialize
f = Field.new(Width, Height)
f.generate(150)
if ARGV[0] == "-r"
@obelisk68
obelisk68 / turtle_sample3a.rb
Created February 17, 2018 13:24
再帰曲線(ゴシック・フリーズ)描画のアニメーション版
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)
@obelisk68
obelisk68 / q50a.rb
Last active February 14, 2018 05:40
アルゴリズム・パズル q50 のすべてのルートの画像化
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
@obelisk68
obelisk68 / show_route.rb
Created February 13, 2018 17:08
アルゴリズム・パズル q50 の求めるべき最長ルートの画像作成
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
@obelisk68
obelisk68 / janken.go
Created February 12, 2018 12:04
Go言語でじゃんけんゲーム
package main
import "fmt"
import "math/rand"
import "time"
type Player struct {
name string
point byte
hand byte
}