{{ message }}

Instantly share code, notes, and snippets.

# obelisk68

Last active Jan 25, 2021

View RPLExamples_1-1.rb
 module Sudoku class Puzzle ASCII = ".123456789" BIN = "\000\001\002\003\004\005\006\007\010\011" def initialize(lines) if (lines.respond_to? :join) s = lines.join else s = lines.dup
Last active Jan 24, 2021

View sokoban_solver.rb
 module Sokoban Pos = Struct.new(:x, :y) do def dirs [Pos.new(x + 1, y), Pos.new(x, y - 1), Pos.new(x - 1, y), Pos.new(x, y + 1)] end def inspect = "<#{x},#{y}>" def over_there(e) = Pos.new(2 * e.x - x, 2 * e.y - y) def <=>(a) = [x, y] <=> [a.x, a.y]
Last active Oct 23, 2020
StarTrek Game (Ruby)
View startrek.rb
 require "curses" class StarTrek class DisplayIO Width = Curses.cols UpperH = 10 def initialize Curses.init_screen Curses.noraw
Last active Aug 12, 2020
Ruby2D を使ったテトリス
View tetris_for_Ruby2D.rb
 require "ruby2d" include Ruby2D::DSL Wait = 18 class Tetromino def initialize @pat = Array.new(4) pats = [["1111"], ["11", "11"], ["011", "110"], ["110", "011"], ["100", "111"], ["001", "111"], ["010", "111"]]
Last active May 17, 2020

View max_heap.rb
 Node = Struct.new(:key, :value) class MaxHeap def initialize @heap = [nil] @size = 0 end attr_reader :heap, :size def insert(key, value)
Last active May 4, 2020
GTK+ で落書き 15
View oekaki_sample19a.rb
 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|
Last active May 4, 2020

View liar_another.rb
 imp = ->(p, q) {!p || q} eqv = ->(p, q) {!(!p ^ !q)} def output(say, cond) trans = ->(ary) {"[#{ary.map {|f| f ? "T" : "F"}.join(" ")}]"} puts [trans.(say), trans.(cond)].join(" ") end cond = Array.new(5) result = (1 << 5) - 1
Last active Apr 27, 2020
AOJ 0192: Multistory Parking Lot
View aoj_0192.rb
 class Car num = 1 define_method(:initialize) do |wait_time:| @num = num num += 1 @wait_time = wait_time end attr_reader :num, :wait_time
Last active Dec 29, 2019
findコマンドのGUI化
View file_search
Last active Nov 14, 2019
Gray_Scott を Gtk でアニメーション表示
View gray_scott_gtk.rb
 require 'numo/narray' require 'gtk3' include Numo SPACE_GRID_SIZE = 256 VISUALIZATION_STEP = 8 Dx = 0.01 Du = 2e-5 Dv = 1e-5