Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Joseph-Bake / fish5.hs
Last active February 12, 2017 12:15
fish number ver.5
-- fish number ver.5
type Flist = [[Integer]]
f5 :: Integer -> Integer
f5 x = m ([replicate (fromInteger x) 1],x)
m :: (Flist,Integer) -> Integer
m (b,x) = mRev (reverse (map (reverse.rm (<0)) b), x)
mRev :: (Flist,Integer) -> Integer
@Joseph-Bake
Joseph-Bake / Consts.hs
Created May 30, 2017 13:29
セルオートマトン
-- constants
module Consts where
-- 近傍数 nn (自身+その横nnマスをもとに次の世代へ発展させる)
nn :: Integer
nn = 5
-- 状態数 q (セルが取れる状態数)
q :: Integer
@Joseph-Bake
Joseph-Bake / ListOperation.hs
Last active July 4, 2017 14:57
ListOperation
type I = Integer
type M = [I]
g :: (M,I) -> I
g ([],x) = x
g (0:as,x) = f$g (as,x) where f y = y+1
g (a:as,x) = g (clone l1 (g (as,x))++l2,x)
where
(l1,l2) = t$span (a<=) as
t (lis,[]) = (lis,[])
type I = Integer
type M = [I]
g :: (M,I) -> I
g ([],x) = x
g (0:as,x) = f$g (as,x) where f y = y+1
g (a:as,x) = g (clone l1 (g (as,x))++l2,x)
where
(l1,l2) = t$span (a<=) as
t (lis,[]) = (lis,[])
@Joseph-Bake
Joseph-Bake / worm.hs
Created July 17, 2017 14:42
ベクレミシェフの虫
type I = Integer
g :: [I] -> I -> I
g [] x = x-1
g (0:as) x = g as (f x) where f y = y+1
g (a:as) x = g (clone l1' (x+1)++l2) (x+1)
where
clone list 1 = list
clone list k = list ++ clone list (k-1)
(l1,l2) = span (a<=) as
@Joseph-Bake
Joseph-Bake / pfgh.hs
Last active July 19, 2017 19:43
急増加関数もどき
type I = Integer
pfgh :: [I] -> I -> I
pfgh list x | null l2 = x+1
| null l1 = fpow (pfgh (head list -1 : tail l2)) x x
| otherwise = pfgh (init l1 ++ [x] ++ (head l2 -1) : tail l2) x
where
(l1,l2) = span (<=0) list
fpow :: (a -> a) -> I -> (a -> a)
@Joseph-Bake
Joseph-Bake / fish3.hs
Last active July 28, 2017 16:52
ふぃっしゅ数ver.3
type I = Integer
data F3 = S [I] | SS I deriving Show
sss :: [F3] -> I -> I
sss [] _ = 0
sss (S []:ns) x = sss ns x
sss [S [1]] x = fpow f x x where f y = y+1
sss (S (1:ns):nss) x = fpow (sss (S ns:nss)) x x
sss (S (n:ns):nss) x = sss (S (n'++ns):nss) x where n'=replicate (fromIntegral x) (n-1)
sss (SS 1:nss) x = sss (S [x]:nss) x
@Joseph-Bake
Joseph-Bake / fish3w.hs
Last active July 29, 2017 13:46
ふぃっしゅ数ver.3の展開
type I = Integer
data F3 = S [I] | SS I
instance Show F3 where
show (S x) = show x
show (SS x) = show x
sss :: [F3] -> IO I -> IO I
sss [] x = do
x' <- x
@Joseph-Bake
Joseph-Bake / dual.py
Created July 15, 2018 13:24
二重数の自動微分
import math
from numbers import Number
class Dual:
def __init__(self,z):
(self.x,self.y) = z
def __str__(self):
if self.y >= 0 :
inivels = (0,-1)
fp = open('col.dat','w')
def col(vels,a):
(u,v) = vels # u : small ball || v : large ball
uu = ((1-a)*u + 2*a*v)/(1+a)
vv = (2*u + (a-1)*v)/(1+a)
return (uu,vv)
def cols(vels,a):