Skip to content

Instantly share code, notes, and snippets.

@obelisk68
obelisk68 / startrek.rb
Last active October 23, 2020 02:04
StarTrek Game (Ruby)
require "curses"
class StarTrek
class DisplayIO
Width = Curses.cols
UpperH = 10
def initialize
Curses.init_screen
Curses.noraw
@obelisk68
obelisk68 / sokoban_solver.rb
Last active January 24, 2021 14:29
倉庫番ソルバー(Brute Force)
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]
@obelisk68
obelisk68 / another_sudoku_solver.rb
Last active March 25, 2022 04:21
数独ソルバー
module Sudoku
Size = 81
Length = 9
INDEXS = [0, 3, 6, 27, 30, 33, 54, 57, 60]
.map { |i| [i, i+1, i+2, i+9, i+10, i+ 11, i+18, i+19, i+20] }
class CertainMap
def initialize(ary)
@field = ary
@obelisk68
obelisk68 / union_find1.rb
Last active April 18, 2023 06:35
Union Find
#簡素版
class UnionFind
def initialize(size)
@rank = Array.new(size, 0)
@parent = Array.new(size, &:itself)
end
def unite(x, y)
x = root(x)
@obelisk68
obelisk68 / blackjack2.rb
Last active December 28, 2024 17:48
ブラックジャックのOOP版
module BlackJack
class Person
def initialize(deck) = @cards = deck.hand_out(2)
def [](i) = @cards[i]
def natural21?
if calc_point == 21
puts "#{self.name}はナチュラル21です"
true
else