- 集合っぽいもののそれぞれの要素にいろいろできるやつ
- http://docs.ruby-lang.org/ja/2.2.0/class/Enumerable.html
※分類は主観が入ってます
module MaxSubseq (maxSubseq) where | |
import Prelude hiding (seq, sum) | |
data Seq = Seq { seq::[Double], sum::Double } deriving Show | |
instance Eq Seq where | |
(Seq _ x) == (Seq _ y) = x == y | |
instance Ord Seq where | |
(Seq _ x) <= (Seq _ y) = x <= y |
※分類は主観が入ってます
class Celebrity | |
attr_reader :matrix | |
def initialize(rows) | |
@matrix = rows | |
end | |
def knows?(from, to) | |
@matrix[from][to] == 1 | |
end |
import Data.List ((\\)) | |
import qualified Data.Map as Map | |
prune :: Ord k => Map.Map k k -> Map.Map k k | |
prune m = _prune m orphans | |
where | |
_prune m [] = m | |
_prune m os = prune $ foldl (flip Map.delete) m os | |
orphans = (Map.keys m) \\ (Map.elems m) |
defmodule Chapter5 do | |
def polynomial2(as, x) do | |
Stream.iterate(1, &(&1 * x)) | |
|> Enum.zip(as) | |
|> Enum.map(fn {x, a} -> x * a end) | |
|> Enum.sum | |
end | |
def polynomial3(as, x) do | |
Enum.reverse(as) |> Enum.reduce(&(&2 * x + &1)) |
require 'sudden_death' | |
module Lita | |
module Handlers | |
class Suddendeath < Handler | |
route /^(突然の.*)/, :sudden_death, command: false | |
def sudden_death(response) | |
response.reply response.match_data[0].sudden_death | |
end |
TAX_RATE = 1.08 | |
# 「1.08 を掛けて→小数点以下を切り捨てる」という演算で target を超えない最大の数値を求める | |
# 戻値 [t: Fixnum, d: Fixnum, i: Fixnum, s: Fixnum] | |
# | |
# t: 元々の税込み価格 (= target) | |
# d: 求める税抜き価格 | |
# i: 計算結果の税抜き価格に税を乗せた価格 | |
# s: 差分 (t - i) | |
# |
// http://qiita.com/t_uda/items/1969e09a970d71e4cfd6 | |
function hoge(x) { | |
switch (true) { | |
case x < 0: | |
console.log(x + " は自然数ではありません."); | |
break; | |
case x === 0: | |
console.log("ここでは 0 は自然数です."); | |
break; |
# Example Answer to http://qiita.com/jnchito/items/c4a56046be1096c19b1c | |
def count_by_word(str) | |
raise ArgumentError, 'str should be a string' unless str.is_a? String | |
str.split.reduce(Hash.new(0)) {|rs, w| rs.merge(w => rs[w] + 1) } | |
end | |
describe "count_by_word" do | |
let(:results) { count_by_word(string) } |