Skip to content

Instantly share code, notes, and snippets.

@haiiro-shimeji
haiiro-shimeji / gist:3910525
Created October 18, 2012 08:48
prototypeのプロパティにオブジェクトを代入しちゃだめ
var Hoge = function() {}
Hoge.prototype = {
hoge: "foo",
fuga: []
}
test( "hoge", function() {
var h1 = new Hoge()
@haiiro-shimeji
haiiro-shimeji / gist:4450006
Last active December 10, 2015 14:49
last' でした^^;;;
last' :: [a] -> a
last' (x:[]) = x
last' (x:xs) = last' xs
@haiiro-shimeji
haiiro-shimeji / gist:4450230
Last active December 10, 2015 14:48
素数判定(試し割り)
isPrime :: Int -> Bool
isPrime 1 = False
-- 約数リストを作成し、それが1,xのみである(それ以外の約数リストがnull)かどうかを判定して返却
--
-- lazy evaluation(怠惰な評価)で、最初の約数がリストに入れられた時点で
-- null評価されFalseを返すことを期待しているが、そうなのか?
--
isPrime x = null [f| f<-[2..x-1], 0 == mod x f]
@haiiro-shimeji
haiiro-shimeji / gist:4453127
Last active December 10, 2015 15:18
エラトステネスのふるい
primenumber :: Int -> [Int]
primenumber x
| 1 > x = error "argument 0 must be >0."
| 1 == x = []
primenumber x = sieve [2..x]
where
s = (sqrt . fromIntegral) x
sieve :: [Int] -> [Int]
sieve (x:[]) = x : []
sieve all@(x:xs)
@haiiro-shimeji
haiiro-shimeji / gist:4460480
Last active December 10, 2015 16:18
fizzbuzz
fizzbuzz xs =
let fb x
-- fb x 以下のブロックになるので、fb x よりも深いインデントが無いとエラー
| 0 == mod x 15 = "FizzBuzz"
| 0 == mod x 5 = "Buzz"
| 0 == mod x 3 = "Fizz"
| otherwise = show x
in [ fb x | x <- xs ]
fizzbuzz'' xs =
@haiiro-shimeji
haiiro-shimeji / gist:4471629
Last active December 10, 2015 17:59
histogram
import Data.List (sort)
-- make histogram
--
-- @param xs [Double] Data array
-- @param delta Double histogram's step width.
-- @param pivot Double
--
histogram :: Double -> Double -> [Double] -> [(Double,Int)]
-- sortすると遅くなりそうだけど、再代入できないからこんな感じなのかな
@haiiro-shimeji
haiiro-shimeji / gist:4471941
Last active December 10, 2015 18:08
時系列データ型
module Data (
TimeSeries(..)
) where
data TimeSeries a = TimeSeries {
delta :: a
, dataArray :: [a]
} deriving (Show)
computeDerivative :: (Floating a) => TimeSeries a -> TimeSeries a
@haiiro-shimeji
haiiro-shimeji / gist:4473110
Last active December 10, 2015 18:18
Mathematics
data Vector3 a = Vector3
(
a,
a,
a
) deriving (Show, Eq)
data Matrix3 a = Matrix3
(
(a, a, a),
(a, a, a),
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.touchtest"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
<activity android:name="MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen">
<intent-filter>
@haiiro-shimeji
haiiro-shimeji / BernoulliTrial.hs
Last active December 11, 2015 04:39
ベルヌイ試行・二項分布
module Bernoulli (
f,
p,
c,
bp,
be,
bv
) where
{--