2008-05-01ãã1ã¶æéã®è¨äºä¸è¦§
http://www.thinkit.co.jp/article/74/2 http://d.hatena.ne.jp/guyon/20080528/1211986261 ãè¦ã¦ããããããã ã£ãã®ã§ããã£ã¦ã¿ã¾ããï¼ï¼ã ãã¦ããã㨠Så¼ã§è¡¨ããhtmlãå®éã®htmlã«å¤æãã¦åºåããã Så¼ã§è¡¨ããhtml (define gauche-page '(htmâ¦
éä¸ãããã¡ã¤ã«ã2ã¤ã«åå²ããã useãä¸åº¦èªã¿è¾¼ãã ãã¡ã¤ã«ãå度èªã¿ãã¾ãªããã¨ã«æ°ã¥ããªãã£ãã ãã°ãããã©ããã¦å¤æ´ãåæ ãããªããã ããã¨èãã¦ãã¾ã£ãã (ãã¨ãé¢åã ã£ãã®ã§util.queueã使ãã¾ããï¼ï¼ï¼ (use lc-module); lc-moduâ¦
以ä¸ã®ãããªããã·ã¥ãä½ããã¨ã§ãpascalã®3è§å½¢ã®å¤ãè¨ç®ã§ããã pascal = Hash.new do |h,n| if n <= 1 h[n] = [1] else h[n] = [0,*h[n-1]].zip([h[n-1],0].flatten).map{ |x,y| x + y} end end #require 'benchmark' #Benchmark.bmbm do |x| # n = 1â¦
è¨ç®æéããããªã æ¨æ¥ã®ãã¨ã¯åéããããã§ããã³ã¡ã³ãããããã¾ããã é¢æ°ã®å¦çæéãçãããã¨ãå®éã®é¢æ°ä»¥å¤ã®é¨åã§ããããæéããããã åãå¦çãä½åº¦ãç¹°ãè¿ããããã¦é¢æ°ã®å¦çæéãé·ãããã¨ããã ã©ãããããååãªå¦çæéâ¦
sicpã§ãã£ãfibonachiæ°ã®è¨ç®ã®memoåãrubyã§ããã¦ã¿ã rubyã®ã³ã¼ã class Memoize def initialize @a = [] end def memo_fib n @a[n] = @a[n] || fib(n) end def fib n case n when 0 0 when 1 1 else fib(n-2) + fib(n-1) end end end #benchmarkç¨ mâ¦
memoå (define (make-table) (let ((table (cons '*table* '()))) (define (insert! key value) (let ((record (assoc key (cdr table)))) (if record (set-cdr! record value) (set-cdr! table (cons (cons key value) (cdr table)))))) (define (lookup kâ¦
2åæ¨ã®ã¬ã³ã¼ã keyã¯ä¸ã¤ããã¨ããªãã ãããªæãã§ããã®ããªï¼ (define (make-tree-table init) (let ((tree (list init '() '()))) (define (make-tree x left right) (list x left right)) (define (entry tree) (car tree)) (define (left tree) (câ¦
3.24 equal?以å¤ã®è¿°èªãã¨ãããã«ããã é¢æ°ãåãåãããã«ãã¦ã¿ãã (define (make-table . key) (let ((local-table (list '*table*)) (same-key? equal?)) (define (assoc key records) (cond ((null? records) #f) ((same-key? key (caar records)â¦
libreadline-devãå¿ è¦ sudo aptitude install libreadline-dev sudo ./configure --program-suffix=1.9 && sudo make && sudo make install
delete-rear-queue!ããªããã°ã次ã®å¤ã ãä¿æãããããªãã¼ã¿æ§é ã§O(1)ã®å¦çãã§ããã ï¼delete-rear-queue!ã ãã¯O(N)ã«ãªã£ã¦ãã¾ããï¼ (define (make-queue) (let ((front-ptr '()) (rear-ptr '())) (define (set-front-ptr! item) (set! front-ptâ¦
(define (front-ptr queue) (car queue)) (define (rear-ptr queue) (cdr queue)) (define (set-front-ptr! queue item) (set-car! queue item)) (define (set-rear-ptr! queue item) (set-cdr! queue item)) (define (empty-queue? queue) (null? (front-ptâ¦
gaucheã®æ¹ãæ¸ããããã£ãã§ãã å¦çãé ã®ä¸ã§åå²ãããããããªæ°ããã¾ãã (define (f seed) (define (enhance l) (map (lambda (x) (if (list? x) (enhance x) (map (cut * x <>) seed))) l)) enhance) (define (ntimes-function f n) (lambda (x) â¦
rubyãå§ããæã«ããããåºåããããã°ã©ã ãä½ã£ãããã¾ããã ããã¯ãããªæãã§æ¸ããã¨æãã¾ãã (9*9ãããªãããnnããããã¾ããï¼ï¼) def kuku n (1..n).map{ |x| (1..n).map{ |y| x * y}} end kuku(2) # => [[1, 2], [2, 4]] ããã¯n*nã®è¦ç´ â¦
2åæ¨ã måæ¨ã«ããã(ä»ã¯2ã ãï¼ æãæ¹åãå¤ããã(ä»ã¯ä¸æ¹åã ãï¼ open Graphics let f x0 y0 r = let draw x y = draw_segments [|(x0, y0, x0+x, y0+y)|]in draw (-r) r; draw r r let rec g x y n r= match (n,r) with (0,_) -> () | (_,0) -> ()â¦
ocamlã®ããã°ã©ã ãå®è¡ããã«ã¯ãcompileãå¿ è¦ã§ãã ããã¦ãcompileæã«ä½¿ã£ãã¢ã¸ã¥ã¼ã«ã®ãã¡ã¤ã«åãæå®ããªããã°ãªããªãã§ãã ä¾ãã°ããããªæãã§ã*1ã #unixã¢ã¸ã¥ã¼ã«ã¨graphicsã¢ã¸ã¥ã¼ã«ã使ç¨ããæ #ä½ã£ããã¡ã¤ã«ã®ååã¯test1.ml oâ¦
open Graphics let f n = let g x = Random.int x in let getcolor () = rgb (g 255) (g 255) (g 255) in let rec loop n = match n with 0 -> () | n -> set_color(getcolor ()); fill_circle (g (size_x ())) (g (size_y ())) (g 50); loop (n - 1) in looâ¦
ocamlãä¸çªçµµãæãã®ãç°¡åãªè¨èªããããã¾ããã æ¨æºã§ãçµµãæãããã®ã¢ã¸ã¥ã¼ã«ãã¤ãã¦ãã¾ãã (* draw.ml *) (* graphics.cma 㨠unix.cmaã使ã *) open Graphics let color_size = 255 let rec plot_graph x (r,g,b) n f= let rec loop (r,g,b)â¦