Skip to content

Instantly share code, notes, and snippets.

#Monty Hall Dilemma
class Monty
def initialize(i)
@door = [:goat, :goat, :car]
@trial_time = i
end
def first_choice
return rand(@door.size)
end
team_mem = Hash.new{|h,k|h[k] = [ ]}
id_team = Hash.new{ }
id = [ ]
id_name = Hash.new{ }
tmp_team = ""
print "team? : "
tmp_team = gets.chomp!
#include <map>
#include <unordered_map>
using namespace std;
typedef pair<int, int> key_type;
int main(){
unordered_map<key_type,int> nemui;
nemui[key_type(1, 1)] = 100;
}
describe Hoge do
before do
@h = Hoge.new
end
describe Hoge, "メソッドAについて" do
it "0には1を返す" do
@h.method_a(0).should == 1
end
end
end
describe Hoge do
before do
@h = Hoge.new
end
describe Hoge, "メソッドAについて" do
it "0には1を返す" do
@h.method_a(0).should == 1
end
end
end
#include <iostream>
using namespace std;
class TEST1{
typedef int id;
public:
A(){};
void set(id n){
x = n;
};
def fact(x)
x > 1 ? x * fact(x-1) : 1
end
def f(x)
return fact(x).to_s.reverse.scan(/^0+/).to_s.size
end
if $0 == __FILE__
p f(ARGV[0].to_i)
require 'rubygems'
require 'mechanize'
require 'hpricot'
require 'open-uri'
agent = Mechanize.new
agent.user_agent_alias = 'Windows IE 7'
page = agent.get("https://twitter.com/login")
f = page.forms[0]
f["session[username_or_email]"] = "username"
# -*- coding: utf-8 -*-
$KCODE='u'
t_a = "釣りゲームはGree".split(//)
s = t_a.size
c = ""
ARGV[0].to_i.times do |i|
c += t_a[0..rand(s).to_i].join("")
end
c += "、無料です"
puts c
class Object
def to_i_or_nil
if self.nil?
return nil
else
return self.to_i
end
end
end