This file contains 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
#Monty Hall Dilemma | |
class Monty | |
def initialize(i) | |
@door = [:goat, :goat, :car] | |
@trial_time = i | |
end | |
def first_choice | |
return rand(@door.size) | |
end |
This file contains 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
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! |
This file contains 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
#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; | |
} |
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
#include <iostream> | |
using namespace std; | |
class TEST1{ | |
typedef int id; | |
public: | |
A(){}; | |
void set(id n){ | |
x = n; | |
}; |
This file contains 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
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) |
This file contains 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
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" |
This file contains 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
# -*- 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 |
This file contains 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
class Object | |
def to_i_or_nil | |
if self.nil? | |
return nil | |
else | |
return self.to_i | |
end | |
end | |
end |