Skip to content

Instantly share code, notes, and snippets.

View memetor's full-sized avatar

memetor memetor

  • Tokyo, Japan
View GitHub Profile
require 'set'
require 'benchmark'
# CHAR = ['0'..'9', 'a'..'z', 'A'..'Z'].map(&:to_a).reduce(&:+)
# seeds = 1000000.times.map {100.times.map {CHAR.sample}.reduce(&:+)}.join("\n")
# File.write('seeds.txt', seeds)
seeds = File.read('seeds.txt').split
Benchmark.bmbm do |x|
numbers = [5, 6, 7, nil, 9]
numbers.sort_by {|n| n ? [0, n] : [1, n]}
#=> [5, 6, 7, 9, nil]

AVA Ratingの仕様

データソース

クラン戦結果で得られる試合結果全て。

クランのレーティング計算式

レートRA,RBを保持するA,Bが対戦しAが勝利した場合

ZEN_KAKU_NUM = %w(0 1 2 3 4 5 6 7 8 9)
HAN_KAKU_MAP = ZEN_KAKU_NUM.map.with_index {|n, i| Hash[n, i.to_s]}.reduce(&:merge)
%(0120x).gsub(/[#{ZEN_KAKU_NUM}]/, HAN_KAKU_MAP)
# => 0120x
<!-- header -->
<title><%= yield(:title) + ' - ' if content_for?(:title) %>MySite</title>
<!-- view -->
<% content_for :title do %>
<%= h @object.name %>
<% end %>
# cf. http://www.slideshare.net/esehara/for-38276816
# 1
i = 1
while i <= 10 do
puts i
i += 1
end
# 2
module TSV
extend self
def parse(str)
str.split("\n").map {|x| x.split("\t")}
end
end
class Object
def to_tsv
return to_s unless kind_of? Enumerable
#!/usr/bin/env ruby
# For OS X
require 'optparse'
class NilClass
def present?
false
end
end
class Fixnum
def fizzbuzz
return 'FizzBuzz' if self % 15 == 0
return 'Buzz' if self % 5 == 0
return 'Fizz' if self % 3 == 0
self
end
end
puts (1..100).map(&:fizzbuzz).join("\n")