Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Joseph-Bake / m.cpp
Last active June 11, 2020 16:35
mirror
#include <iostream>
#include <cmath>
#include <vector>
#include <fstream>
#include <functional>
double fp(double phi, double a, double x, double y) {
return std::tan(0.5 * (phi + std::atan(y / (x - a))));
}
@Joseph-Bake
Joseph-Bake / ZigZagNumber.py
Created March 9, 2020 12:05
Zig-Zag Number ねげろんさんのを改造
import itertools
import numpy
def getZigZagNumber(num):
# 0, 1, 2番目のZig-Zag Numberは1と定義
if (num == 0) or (num == 1) or (num == 2):
return 1
else:
alterPerm = 0
for perm in itertools.permutations(list(range(num))):
frontSign = 0
@Joseph-Bake
Joseph-Bake / zig-zag_num.py
Last active March 8, 2020 11:07
Zig-Zag Number
#ある数より前のリストl1から選ぶよ
#ある数より後ろのリストはl2だよ
def choose_l1(l1,l2,zigzaglist):
global zigzagnum,write_flag
#前のリストがなかったら終わるよ
if l1==[]:
if l2==[]:
zigzagnum +=1
return 1
else:
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):
@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 :
@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 / 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 / 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 / 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
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,[])