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 MyHashFunction | |
# 古典的なハッシュ関数、One-at-a-Time Hash | |
# 参考:http://www.burtleburtle.net/bob/hash/doobs.html | |
def one_at_a_time(key) #keyは文字列を想定 | |
hash = 0 | |
key.each_char {|ch| #文字を取り出す | |
hash += ch.ord | |
hash += (hash << 10) | |
hash ^= (hash >> 6) | |
} |
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 './hash_function' | |
require './tablesize' | |
# ハッシュ関数を用いた連想配列(ハッシュテーブル)の実装 | |
class MyHashTable | |
def initialize() | |
@arr = Array(TABLESIZE) | |
end | |
# keyは文字列を想定 |
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 MyAssociativeArray < Array | |
def []= (k, v) | |
found = false | |
self.each {|item| | |
if item[0] == k then | |
item[1] = v | |
found = true | |
break |
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
##CSVを使う方法 | |
##データフレーム読み込み | |
df <- read.csv("data/sales_temp.csv",header=T) | |
##(売上と気温からなる)新しいデータフレームを作成 データフレームの作成参照 http://rplus.wb-nahce.info/rsemi_stat_basic/r_nijigendata.html | |
soukan <- data.frame(x=df["temperature"], y=df["sales"]) |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
def max_function(x, a_set): | |
list = [] | |
for a in a_set: | |
list.append(abs(x - a)) | |
return max(list) | |
#より一般的に書くなら |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class MyElevator(): | |
def __init__(self, user_distribution): | |
self.user_distribution = user_distribution | |
def calculate_loss(self, stand_by_floor): #各待機階について損失関数値を求める | |
sum_of_losses = 0 | |
for floor, number_of_users in self.user_distribution.items(): |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class MyElevator(): | |
def __init__(self, user_distribution): | |
self.user_distribution = user_distribution | |
def find_optimal_stand_by_floor(self): #最適待機階を求める(中央値を求めるだけ) | |
total_number_of_users = 0.0 | |
for number_of_users in self.user_distribution.values(): |
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
#!/bin/bash | |
# ./render-template.sh srcdir dstdir | |
set -e | |
trap 'echo "ERROR $0 ($LINENO)" 1>&2' ERR | |
basedir=$(cd $(dirname $0) && pwd) | |
project_dir=$basedir/.. | |
_ENV_VARS=( |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import Queue | |
class MySubDictionary(): | |
volume = 0 #現存するDictonary(i.e. ノード)の数 | |
def __init__(self, number, prefix, suffixes): | |
MySubDictionary.volume += 1 | |
self.number = number |
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class MySubDictionary(): | |
volume = 0 #現存するDictonary(i.e. ノード)の数 | |
def __init__(self, prefix, suffixes): | |
self.number = MySubDictionary.volume | |
MySubDictionary.volume += 1 | |
self.prefix = prefix | |
self.suffixes = [] |
NewerOlder