This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'r2d' | |
include Math | |
w = window | |
x1, y1 = cos(0)*200+w.w/2, -sin(30*PI/180)*200+w.h/2 | |
1.upto(360) {|deg| | |
rad = deg*PI/180 | |
x2, y2 = cos(rad)*200+w.w/2, -sin(2*rad+30*PI/180)*200+w.h/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# Ruby 2.0以降では以下でも大丈夫でした。 | |
module Hoge | |
class Piyo | |
def initialize(x, y) | |
@x = x; @y = y | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# 『有限と微笑のパン』で塙理生哉が西之園萌絵に出題する問題 | |
# (1) この5文字(A E H R T)でできるすべての文字列は? => 120 | |
# (2) アルファベットに並べると、地球は何番目? => 28 | |
# (3) 55番目は? => ? | |
alphabets = %w(A E H R T) | |
# (1) | |
alphabets.permutation.size # => 120 | |
# (2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
require 'optparse' | |
def get_networkaddress arg | |
addr, len = arg.split('/') | |
addr_arr = addr.split('.').map(&:to_i) | |
ret = (addr_arr[0] << 24 | addr_arr[1] << 16 | | |
addr_arr[2] << 8 | addr_arr[3]) & ~((1 << (32 - len.to_i)) - 1) | |
"NETWORK=#{(ret >> 24) & 255}.#{(ret >> 16) & 255}.#{(ret >> 8) & 255}.#{ret & 255}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'open-uri' | |
require 'nokogiri' | |
require 'gdbm' | |
vol = ARGV.shift | |
GDBM.open("reibun.db") do |db| | |
if db[vol] | |
todays_example = db[vol] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# coding: utf-8 | |
# 接尾辞リストを作る | |
def tails xs | |
ret = [''] | |
xs.chars.each_index {|i| | |
ret << xs[i..-1] | |
} | |
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub Macro1() | |
j = 2 | |
For i = 2 To 241 | |
For k = 1 To 8 | |
Sheets("個票").Cells(j, k).Value = Sheets("一覧").Cells(i, k).Value | |
Next | |
j = j + 3 | |
Next | |
End Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fun op, x, y | |
send(op, x, y) | |
end | |
def add x, y | |
x + y | |
end | |
def sub x, y | |
x - y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
MAX = 1_000_000 | |
data = [[*1..10, 100, 1000, 10000, 100000, MAX], | |
[*1..10, 100, 1000, 10000, 100000, MAX], | |
[*1..10, 100, 1000, 10000, 100000, MAX]] | |
# (1 + 1/n)**n の計算 | |
data[1].map!{|n| | |
(1 + 1.0 / n)**n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 目的:あらかじめ昇順に並んでいる整数リストlstと整数nを受け取り昇順となる位置にnを挿入したリストを返す *) | |
(* insert: int list -> int -> int list *) | |
let insert lst n = match lst with | |
[] -> [n] | |
| first :: rest -> | |
if n <= first then | |
n :: first :: rest | |
else | |
first :: (insert rest n) | |
OlderNewer