Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / es_sample1.rb
Last active December 12, 2018 18:14
ANSIエスケープシーケンスで遊ぶ
require_relative 'es'
L = 14 #一辺の長さ(偶数にする)
print ES.safe_scroll(L)
i = 0
x, y = ES.cursor_position
x -= 1
square = ->(width) {
@obelisk68
obelisk68 / root.rb
Last active November 16, 2018 15:57
平方根の計算
require 'prime'
module Kernel
def Root(*args)
Root.new(*args)
end
end
module ExRoot
def to_root
@obelisk68
obelisk68 / thirty_one_play.go
Last active October 29, 2018 07:31
31ゲーム
package main
import "fmt"
import "math/rand"
import "time"
var goal = 31
func min_max(cards []int, turn bool, sum int) int {
if sum == goal { if turn {return -10} else {return 10} }
if sum > goal { if turn {return 10} else {return -10} }
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)
@obelisk68
obelisk68 / cairo_sample1.rb
Last active October 19, 2018 01:14
「コマ大数学科」GIFアニメ作成
require 'cairo'
require_relative 'gifanime'
require 'matrix'
include Math
Dir.chdir("picture") #作業用ディレクトリ
Width = 300
Surface = Cairo::ImageSurface.new(Cairo::FORMAT_ARGB32, Width, Width)
C = Cairo::Context.new(Surface)
@obelisk68
obelisk68 / rubysdl_tetris.rb
Last active September 29, 2018 14:04
Ruby/SDL でテトリス
# Gem 'rubysdl' に付属しているサンプルを modify したものです
require 'sdl'
class Object
def deep_clone
Marshal::load(Marshal.dump(self))
end
end
class Pattern
@obelisk68
obelisk68 / μSchemeR_debug.rb
Created August 7, 2018 15:20
μSchemeR関連
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)>],
@obelisk68
obelisk68 / gtk_sample2c.rb
Last active August 4, 2018 01:24
Ruby/GTK+ でちょっと考えた
require 'gtk2'
class GUI < Gtk::Window
Meth = [:wanwan, :nya]
def initialize(&bk)
super("GUI")
set_width_request(200)
box = Gtk::VBox.new
@obelisk68
obelisk68 / prime_table.rb
Last active April 30, 2018 01:42
省メモリで「エラトステネスの篩」同等の結果を得るコード
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
@obelisk68
obelisk68 / linuxmint_backup.rb
Last active April 20, 2018 11:13
home フォルダのバックアップ
require 'fileutils'
class String
def cut
/.+tomoki\/(.+)$/.match(self)[1]
end
end
def get_file_names(f)
dirs = Dir.glob("*")