This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
クロッシング問題をそれぞれHaskell, D, C++で書いた。全てマージソートでマージ中に転倒数を数えていくアルゴリズム。 | |
crossing.hs : 200ms vectorを使って高速化 | |
crossing2.hs : 1200ms listのみを使った | |
crossing.d : 130ms | |
crossing.c++ : 80ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment (getArgs) | |
import Control.Monad (mapM_) | |
import Data.Functor ((<$>)) | |
import Data.String.Utils (replace) -- missingH | |
import System.IO.UTF8 (putStrLn, readFile) -- utf8-string | |
import Prelude hiding (putStrLn, readFile) | |
main :: IO () | |
main = main' =<< getArgs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE FlexibleInstances #-} | |
-- | |
-- head $ decode $ encode [1..] -- : infinite loop | |
-- head $ runLazily $ decode $ encode $ Lazily [1..] -- : 1 | |
-- | |
module Data.Binary.Lazy ( | |
Lazily(..), | |
) where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; The following implementation of rb-tree is based on http://www.cs.kent.ac.uk/people/staff/smk/redblack/. | |
(defun change-to-black (tree) | |
(pattern-match tree | |
((:pattern (_ . rest) :variable rest :ignore _) `(:B . ,rest)) | |
(:otherwise nil))) | |
(defun rb-insert (tree obj cmp) | |
(change-to-black (rb-insert% tree obj cmp))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(DEFPARAMETER *TESTS* NIL) | |
(DEFMACRO EXAMPLE (EXPR _ EXPECT &KEY (TEST '#'EQUALP)) | |
(DECLARE (IGNORE _)) | |
(WITH-GENSYM (RESULT) | |
`(LET ((,RESULT ,EXPR)) | |
(IF (FUNCALL ,TEST ,RESULT ',EXPECT) | |
(FORMAT T "OK: ~a => ~a~%" ',EXPR ,RESULT) | |
(FORMAT T "NG: ~a => ~a, expected ~a~%" ',EXPR ,RESULT ',EXPECT))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(DEFPARAMETER *TESTS* NIL) | |
(DEFMACRO EXAMPLE (EXPR _ EXPECT &KEY (TEST '#'EQUALP)) | |
(DECLARE (IGNORE _)) | |
(WITH-GENSYM (RESULT) | |
`(LET ((,RESULT ,EXPR)) | |
(IF (FUNCALL ,TEST ,RESULT ',EXPECT) | |
(FORMAT T "OK: ~a => ~a~%" ',EXPR ,RESULT) | |
(FORMAT T "NG: ~a => ~a, expected ~a~%" ',EXPR ,RESULT ',EXPECT))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(PROCLAIM '(OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0))) | |
(DEFUN FACT1 (X) | |
"factorial, using DO" | |
(DECLARE (FIXNUM X)) | |
(DO ((FACT-N 1 (THE FIXNUM (* FACT-N N))) | |
(N 1 (1+ N))) | |
((> N X) FACT-N) | |
(DECLARE (FIXNUM FACT-N N)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(PROCLAIM '(OPTIMIZE (SPEED 3) (SAFETY 0) (DEBUG 0))) | |
(DEFUN FACT1 (X) | |
"factorial, using DO" | |
(DECLARE (FIXNUM X)) | |
(DO ((FACT-N 1 (THE FIXNUM (* FACT-N N))) | |
(N 1 (1+ N))) | |
((> N X) FACT-N) | |
(DECLARE (FIXNUM FACT-N N)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(fork) | |
require(gtools) | |
# | |
# socket listen | |
# ゾンビをたくさんつくります。 | |
server.start <- function(port = 3333) { | |
server.pid <<- | |
fork(function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p1 <- page(a("p02"), | |
cmd.img(hist(rnorm(20)), "rnorm20"), | |
cmd(summary(rnorm(10)))) | |
p02 <- page(a("p20"), | |
"タイトル", | |
"environment") | |
p20 <- page(a("p21"), | |
"自己紹介", |
NewerOlder