Skip to content

Instantly share code, notes, and snippets.

@Joseph-Bake
Joseph-Bake / plotrk.png
Last active January 23, 2017 16:06
練習プログラムその2(Haskellでルンゲクッタ)
plotrk.png
@Joseph-Bake
Joseph-Bake / input output
Created January 23, 2017 16:20
練習プログラムその1
入力
3
出力
(><)/ wahoo!
(><)/ wahoo!!
(><)/ wahoo!!!
good bye
@Joseph-Bake
Joseph-Bake / gasshuku.hs
Created January 26, 2017 20:22
合宿問題
import Graphics.Gloss
main :: IO()
main =
animate
(InWindow "合宿問題" (xsize,ysize) (200,200))
white
drawFunc
drawFunc t = pictures [funcs n t | n <- [1..5]]
@Joseph-Bake
Joseph-Bake / Takeuchi.hs
Created January 28, 2017 08:10
竹内関数の可視化
-- Takeuchi Function
import Graphics.Gloss
type Tarai = (Int,Int,Int)
main :: IO()
main =
animate
(InWindow "竹内関数可視化" (600,400) (200,200))
@Joseph-Bake
Joseph-Bake / nTakeuchi.hs
Created January 28, 2017 08:12
n引数竹内関数
-- n次元 Takeuchi Function
type Tarai = [Int]
main :: IO()
main = print $ length $ ntaraiList initarai
ntarai :: Tarai -> Int
ntarai (a:b:xs)
| a <= b = b
| a > b = ntarai (map ntarai (minus1 (krkr (a:b:xs))))
@Joseph-Bake
Joseph-Bake / worm.hs
Last active February 5, 2017 09:41
Beklemishev's worms
-- Beklemishev's worms
worm :: Integer -> [Integer] -> Integer
worm step [] = step
worm step x = worm (step+1) (next step x)
next :: Integer -> [Integer] -> [Integer]
next _ [] = []
next step x
| last x == 0 = init x
@Joseph-Bake
Joseph-Bake / worm2.hs
Created February 5, 2017 18:16
Beklemishev's worms
-- Beklemishev's worms
worm :: Integer -> [Integer] -> Integer
worm step [] = step
worm step x
| x == [1] = 2*step + 3
| length x >= 2 && drop (length x - 2) x == [0,1] = worm (from01 step) (init (init x))
| length x >= 3 && drop (length x - 3) x == [0,1,1] = worm (from011 (step+2)) (init$init$init x)
| otherwise = worm (step+1) (next step x)
@Joseph-Bake
Joseph-Bake / fish1.hs
Created February 6, 2017 15:59
fish number ver.1
type NF = (Integer,Integer -> Integer)
type NFM = (Integer,Integer -> Integer,NF -> NF)
--S変換
s :: NF -> NF
s (m,f) = (g m,g)
where
g :: Integer -> Integer
g n = b n n
b :: Integer -> Integer -> Integer
@Joseph-Bake
Joseph-Bake / fish2.hs
Last active February 7, 2017 13:11
fish number ver.2
type NF = (Integer,Integer -> Integer)
type NFM = (Integer,Integer -> Integer,NF -> NF)
s :: NF -> NF
s (m,f) = (g m,g)
where
g :: Integer -> Integer
g n = b n n
b :: Integer -> Integer -> Integer
b 0 l = f l
@Joseph-Bake
Joseph-Bake / multiAck.hs
Created February 7, 2017 17:52
multivariable Ackermann function
-- multivariable Ackermann function
nAck :: [Integer] -> Integer
nAck [] = 0
nAck x
| length x == 1 = head x + 1
| head x == 0 = nAck (tail x)
| last x == 0 && last (init x) >= 1 = nAck (init (init x) ++ [last (init x)-1,1])
| last x >= 1 && last (init x) >= 1 = nAck (init (init x) ++ [last (init x)-1] ++ [nAck (init x ++ [last x-1])])
| last x >= 0 && snd (y x) >= 1 && last (fst (y x)) >= 1