x 面のダイスがある。それを n 回振り、ダイスの数ごとに出た回数をカウントする。
この時、出た回数が 1 回の目の種類と 2 回以上の目の種類の比率が
1:1 となるには x は何である必要があるか。n を使って表せ。
x = 12 (12 面ダイス)
n = 10 (10 回振った)
export PROMPT=$'%{$fg[magenta]%}|%c|*\'-\'\) %{$reset_color%}' | |
export PROMPT=$'|%{$fg[$NCOLOR]%}%B%n%b%{$reset_color%}:%{$fg[red]%}%30<...<%~%<<%{$reset_color%}|*\'-\'\) %(!.#.$) ' |
// ==UserScript== | |
// @name Highlight followers | |
// @namespace quanon | |
// @version 0.1 | |
// @author QUANON | |
// @match https://twitter.com/following | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
// @grant none | |
// ==/UserScript== |
calc_rems = fn (n) -> {rem(n, 3), rem(n, 5), n} end | |
fizzbuzz = fn | |
{0, 0, _} -> "FizzBuzz" | |
{0, _, _} -> "Fizz" | |
{_, 0, _} -> "Buzz" | |
{_, _, n} -> n | |
end | |
IO.inspect(1..50 |> Enum.map(calc_rems) |> Enum.map(fizzbuzz)) |
module ArrayExtention | |
def reject_if(&block) | |
rejected = [] | |
delete_if do |value| | |
if block.call(value) # or if yield | |
rejected << value | |
true # なくてもいいけど僕の好み的に明示的に true を返したかった。 | |
end | |
end |
module Extension::ActiveRecordExtension | |
extend ActiveSupport::Concern | |
included do | |
# (参考) | |
# OR operator in WHERE clause with Arel in Rails 4.2 | |
# http://stackoverflow.com/questions/27627390/or-operator-in-where-clause-with-arel-in-rails-4-2 | |
# | |
# ActiveRecord::QueryMethods::WhereChain | |
# https://github.com/rails/rails/blob/v4.2.1/activerecord/lib/active_record/relation/query_methods.rb |
// ==UserScript== | |
// @name j-motto Userscript | |
// @namespace quanon | |
// @version 0.1.0 | |
// @author QUANON | |
// @include https://gws45.j-motto.co.jp/* | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
// @grant none | |
// ==/UserScript== |
module GoodName | |
refine(String) do | |
def good_name? | |
true | |
end | |
end | |
def bad_name? | |
false | |
end |
# 使い方: | |
# yml = File.read(path) | |
# yml_to_struct(yml) | |
def yml_to_struct(yml) | |
yml_object = YAML.load(ERB.new(yml).result) | |
yml_object_to_struct(yml_object) | |
end | |
# YAML.load した結果の Object に含まれる Hash を Struct に変換し、 |
require 'benchmark' | |
array = (1..10_000).map { |n| [n] } | |
Benchmark.bm do |x| | |
x.report('map & flatten:') { array.map { |a| a << 'yuno' }.flatten } | |
x.report('map & flatten!:') { array.map { |a| a << 'yuno' }.flatten! } | |
x.report('flat_map:') { array.flat_map { |a| a << 'yuno' } } | |
end |