Skip to content

Instantly share code, notes, and snippets.

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)
}
require './hash_function'
require './tablesize'
# ハッシュ関数を用いた連想配列(ハッシュテーブル)の実装
class MyHashTable
def initialize()
@arr = Array(TABLESIZE)
end
# keyは文字列を想定
# 配列を連想配列化する(強引な)実装
class MyAssociativeArray < Array
def []= (k, v)
found = false
self.each {|item|
if item[0] == k then
item[1] = v
found = true
break
@msato-ok
msato-ok / plot.R
Last active February 1, 2018 11:18
##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"])
#!/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)
#より一般的に書くなら
#!/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():
#!/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():
@msato-ok
msato-ok / render-template.sh
Created December 2, 2017 12:30
bashでsedの置換でテンプレート処理するスクリプト
#!/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=(
#!/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
#!/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 = []