Skip to content

Instantly share code, notes, and snippets.

@hitode909
hitode909 / gist:3871
Created August 4, 2008 10:47
KPLの予約語のArray
View gist:3871
RESERVEDS = %w{ PROGRAM CONST TYPE VAR PROCEDURE FUNCTION
BEGIN END ARRAY OF INTEGER CHAR CALL
IF THEN ELSE WHILE DO FOR TO }
View gist:3910
#! /usr/bin/ruby -Ku
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")
View ngram.rb
require 'pp'
$KCODE = 'UTF8'
module Ngram
def run(str)
analyze(cut(str,3))
end
def cut(str, n)
list = str.split(//)
View put_stone.rb
# /usr/bin/ruby
# -*- coding: utf-8 -*-
# オセロの石を置くプログラム
# based on http://bkc.g.hatena.ne.jp/coconutsfine/20081010/1223651539
# 新しい盤面のArrayを作って返す
def setup_box
# 盤面オブジェクトを生成(8x8の:empty)
box = Array.new(8){ Array.new(8, :empty) }
#盤面の初期値を設定
View boardcomputer01.rb
#! /usr/bin/ruby
def parse(string)
string.each_line do |line|
list = line.split(" ")
print "#{list.first}: "
list[1..-1].each do |token|
raise "input's size should 2(#{token})" if token.size != 2
token.split("").each do |char|
num = char.chomp.hex.to_s(2)
print "#{'0'*(4-num.size%4) if num.size%4 != 0}#{num}"
View gist:16716
class Stone
@@STONE_COLORS = [:white, :black]
def initialize(heads_color)
raise "Invalid type" unless @@STONE_COLORS.include?(heads_color)
@heads = heads_color
end
attr_reader :heads # 表の色
View fibonatti.asm
* N: NUMBER OF INPUT
N: EQU 80H
* CUR: CURRENT RESULT (AND RESULT)
CUR: EQU 81H
* P1: PREVIOUS RESULT
P1: EQU 82H
* P2: PRE-PREVIOUS RESULT
View print_cpp_sources.rb
LINE = "="*80
Dir.glob("*.cpp\0*.h") do |file|
puts LINE
puts " " + file
puts LINE
system("cat -n #{file}")
end
View marcov.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
# マルコフ連鎖をしてみるやつ
$KCODE = 'UTF8'
# Array::choiseを追加
class Array
def choise
self[rand(self.size)]
View .emacs.el
;; default encodingをutf-8に変更
(set-default-coding-systems 'utf-8)
;; status-barにカーソルのcolumn表示(4,29とか)
(column-number-mode t)
;; ファイル名補完で大文字小文字を区別しない
(setq completion-ignore-case t)
;; バックアップファイルを作らない