blogな文化に浸かってから,コードを日記に置きっぱなしで行方不明になりがちです.
せっかくなので,一部回収.

jit-um

ICFPC2006の高速なumが欲しくて作ってみた.
XBYACK使ってJITコンパイルしてます.
自分で普通に書いた物と比べて,3倍以上速いです.
blog/2007-09-22#k55a26a5
blog/2007-09-28#xa37d134

interpreter C

gdbに頼って,C言語インタプリタもどきです.
blog/2007-09-18

HAL研プロコン2007

HAL研のプロコン2007で提出したコードです.
blog/2008-01-17#s2c070ce

pukiwiki関係

正規表現で指定したページ限定RSS

blog/2006-09-04#m7c0bea9

Haskellでライフゲーム

inetdで動かしていたので,telnetなライフゲームになっていました.
今は動いていません.
blog/2006-06-27

  • ソース
    module Main where
    import Foreign
    import Foreign.C
    import Data.Array
    import Control.Concurrent
    import System.Random
    
    foreign import ccall "initscr" initscr :: IO ()
    foreign import ccall "endwin"  endwin  :: IO ()
    foreign import ccall "refresh" refresh :: IO ()
    foreign import ccall "mvaddch" mvaddch :: CInt -> CInt -> Char -> IO ()
    
    instance Ix CInt where
        range (m,n) = [m..n]
        inRange (m,n) i = m <= i && i <= n
        index b@(m,n) i
            | inRange b i   =  fromIntegral (i - m)
            | otherwise     =  error "Ix.index: Index out of range."
    
    width =80
    height=24
    getRange = ((-1,-1), (width, height))
    isIn (x, y)=x>=0 && x<width && y>=0 && y<height
    indexList = range getRange
    
    initWorld = do r <-rnds
                   return $ (temp r)//[((x, y), False) | x<-[-1..width], y<-[-1..height], x== -1||x==width||y== -1||y==height]
        where
          temp r= array getRange $ zip [(x, y) | x<-[-1..width], y<-[-1..height]] r
          rnds= do gx <-newStdGen
                   return $ randomRs (False, True) gx
    
    printCell a p@(x,y) = mvaddch (fromIntegral y) (fromIntegral x) $ if a!p then 'O' else ' '
    printWorld a = mapM (printCell a) $ filter isIn indexList
    
    nextStep a = a//[((x,y), l) | x<-[0..width-1], y<-[0..height-1], l<-[True, False], nextCell x y==l]
        where
          nextCell x y = (count x y==2 && a!(x,y))|| count x y==3
          count x y= length $ filter (==True) (around x y)
          around x y= map (a!) (around' x y)
          around' x y = [(x', y') | x'<-[x-1..x+1], y'<-[y-1..y+1], x'/=x||y'/=y]
    
    mvaddStr _ [] = return ()
    mvaddStr x (c:cx) = do if x < 0 then return()
                                    else mvaddch (fromIntegral $ height `div` 2) (fromIntegral x) c
                           mvaddStr (x+1) cx
    loop a m x | x== -(length m) = return ()
               | otherwise       = do printWorld a
                                      mvaddStr x m
                                      refresh
                                      threadDelay 1000
                                      --c<-getChar
                                      loop (nextStep a) m (x-1)
    
    msg n = head $ drop n msgs
    msgs = ["Life is either a daring adventure or nothing.",
            "Imagination is more important than knowledge."
           ]
    
    main :: IO ()
    main = do initscr
              gx<-newStdGen
              m <- return $ msg $ fst $ randomR (0, length msgs -1) gx
              i <- initWorld
              loop i m width
              endwin
    

昔のもの

vectorの作者紹介ページ
http://www.vector.co.jp/vpack/browse/person/an026074.html