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
| ;; compose、compose2両関数とも同じ動きをするが、生成するラムダ式の構造が違う | |
| ;; (funcall (compose #'not #'evenp #'+) 3 2 2) | |
| ;; T | |
| (defun compose (&rest fs) | |
| (if (null (cdr fs)) | |
| (car fs) | |
| (let ((g (apply #'compose (cdr fs)))) | |
| (lambda (&rest args) (funcall (car fs) (apply g args)))))) |
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
| (defun foldr (f lst) | |
| (if (null (cdr lst)) (car lst) | |
| (funcall f (car lst) (foldr f (cdr lst))))) | |
| (defun foldl (f lst) | |
| (if (null (cdr lst)) (car lst) | |
| (funcall f (foldl f (butlast lst)) (car (last lst))))) | |
| (defun foldr-tail (f a lst) | |
| (if (null lst) a |
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
| ;; [2015-05-11] | |
| ;; C-M-.で進む、C-M-,で戻るが出来る便利関数 | |
| ;; 移動中はミニバッファに状況を表示します | |
| ;; 感想きかせてくれると嬉しいです | |
| (require 'cl) | |
| (defmacro kset (key fn) `(global-set-key (kbd ,key) ,fn)) | |
| (defun substr (str start end) |
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
| ;; 記録: 1時間56分58秒(-_-) | |
| (defn problem1-a [lst] | |
| (let [result (atom 0)] | |
| (doall (for [x lst] (reset! result (+ @result x)))) | |
| @result)) | |
| (defun problem1-b [lst] | |
| (let [result (atom 0) | |
| i (atom 0) |
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
| # 2015-05-31 | |
| # 制限時間3時間で迷路を解く問題 | |
| # http://okajima.air-nifty.com/b/2010/01/post-abc6.html | |
| class Path | |
| attr_accessor :value, :prev, :f, :g, :h | |
| def initialize(value: nil, g: 0, h: 0, prev: nil) | |
| @value = value | |
| @g = g | |
| @h = h |
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
| ;; scheme interpreter | |
| ;; PAIP p714より引用 | |
| ;; CL-USER> (scheme) | |
| ;; ==> (set! fact (lambda (n) (if (= n 0) 1 (* n (fact (- n 1)))))) | |
| ;; #<COMPILED-LEXICAL-CLOSURE (:INTERNAL INTERP) #x2100A5E22F> | |
| ;; ==> (fact 5) | |
| ;; 120 | |
| ;; ==> ((if (= 1 1) * +) 3 4) | |
| ;; 12 |
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
| # coding: utf-8 | |
| # irb(main):286:0> (scheme) | |
| # ==> (+ 1 2) | |
| # 3 | |
| # ==> ((if (equal 1 1) * +) 2 3) | |
| # 6 |
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
| # coding: utf-8 | |
| # irb(main):037:0> (scheme) | |
| # (scheme) | |
| # ==> (* 2 (call_cc (lambda (cc) (set! old_cc cc) 4))) | |
| # 8 | |
| # ==> (old_cc 10) | |
| # 20 | |
| # ==> (+ 1 (old_cc 10)) | |
| # 20 |
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) | |
| interactWith function inputFile outputFile = do | |
| input <- readFile inputFile | |
| writeFile outputFile (function input) | |
| main = mainWith myFunction | |
| where mainWith fn = do | |
| args <- getArgs | |
| case args of |
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
| #+sbcl | |
| (eval-when (:compile-toplevel :execute) | |
| (handler-case | |
| (progn | |
| (sb-ext:assert-version->= 1 2 2) | |
| (setq *features* (remove 'old-sbcl *features*))) | |
| (error () | |
| (pushnew 'old-sbcl *features*)))) | |
| (defun flatten (x) |