This file contains hidden or 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
panda:~ yancya$ echo 'puts :hoge' > hoge.rb | |
panda:~ yancya$ ruby -e 'load "./hoge.rb"' | |
hoge | |
panda:~ yancya$ ruby -e '10.times{load "./hoge.rb"}' | |
hoge | |
hoge | |
hoge | |
hoge | |
hoge | |
hoge |
This file contains hidden or 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
# ruby-1.9.3 | |
n, d = gets.split(" ").map(&:to_i) | |
items = n.times.map{gets.to_i} | |
limits = d.times.map{gets.to_i} | |
limits.each do |limit| | |
indexes = (0..items.size-1).to_a | |
sums = indexes.product(indexes).select{|n, m| n != m}.map{|n, m| items[n] + items[m]} | |
puts sums.uniq.reduce(0){|max, sum| max = sum if max < sum && sum <= limit; max} | |
end |
This file contains hidden or 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
n, d = gets.split(" ").map(&:to_i) | |
items = n.times.map{gets.to_i} | |
limits = d.times.map{gets.to_i} | |
def max_pattern(limit, items) | |
max = 0 | |
items.each_with_index do |first, i| | |
items.each_with_index do |second, j| | |
sum = first + second | |
max = sum if i != j && max < sum && sum <= limit |
This file contains hidden or 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
data = ARGF.read.split("\n") | |
n, d = data.first.split(" ").map(&:to_i) | |
items = data[1..n].map(&:to_i) | |
limits = data[n+1..n+d].map(&:to_i) | |
patterns = [] | |
until items.empty? | |
first = items.pop | |
items.each do |second| | |
patterns << (first+second) |
This file contains hidden or 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
data = ARGF.read.split("\n") | |
n, d = data.first.split(" ").map(&:to_i) | |
items = data[1..n].map(&:to_i) | |
limits = data[n+1..n+d].map(&:to_i) | |
patterns = [] | |
until items.empty? | |
first = items.pop | |
items.each do |second| | |
patterns << (first+second) |
This file contains hidden or 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
data = ARGF.read.split("\n") | |
n, d = data.first.split(" ").map(&:to_i) | |
items = data[1..n].map(&:to_i) | |
limits = data[n+1..n+d].map(&:to_i) | |
patterns = [] | |
until items.empty? | |
first = items.pop | |
items.each do |second| | |
patterns << (first+second) |
This file contains hidden or 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
SELECT t2.count | |
FROM (SELECT t1.created_at | |
,lag(t1.status) over(order by t1.created_at DESC) AS status | |
,lag(t1.count) over(order by t1.created_at DESC) AS count | |
,lag(t1.status) over(order by t1.created_at DESC) <> t1.status AS judge | |
FROM (SELECT status | |
,created_at | |
,count(id) over(partition by status order by created_at DESC) | |
FROM items | |
) as t1 |
This file contains hidden or 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
ruby -rsinatra -rjson -e 'get "/" do; %w{hoge fuga moge}.to_json; end' |
This file contains hidden or 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
module BinaryPrefix | |
refine Fixnum do | |
UNIT_TYPES = { | |
kib: 10, # Kibi Byte | |
mib: 20, # Mebi Byte | |
gib: 30, # Gibi Byte | |
tib: 40, # Tebi Byte | |
pib: 50, # Pebi Byte | |
eib: 60, # Exbi Byte | |
zib: 70, # Zebi Byte |
This file contains hidden or 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
h = {a: 1, b: 2, c: 3} | |
h.define_singleton_method(:only, ->(*syms){self.select{|o| syms.member? o}}) | |
h.only(:a, :c) #=> {:a=>1, :c=>3} | |
#作るしかないかも |