2008-02-01ãã1ã¶æéã®è¨äºä¸è¦§
1000ã®å ´å guile> (search-for-primes 1000 30) 1001 1003 1005 1007 1009 *** 62 1011 1013 *** 63 1015 1017 1019 *** 62 1021 *** 63 1023 1025 1027 1029 1031 *** 63 1033 *** 47 1035 1037 1039 *** 62 1041 1043 1045 1047 1049 *** 46 1051 *** 63 â¦
ããé¢ç½ããªã£ã¦ãããç´ æ°ãæ±ããã®ã«å¿ è¦ãªæéã調ã¹ãèå¯ããCè¨èªãªãåç´ãªforã«ã¼ãã«ãªãã³ã¼ãã ããLispã ã¨æ«å°¾å帰ã使ã£ã¦è§£ãå¿ è¦ãããã æ®å¿µãªããèªåã§æ¸ããã¨ã¯åºæ¥ãªãã£ã®ã§ãAnswerBookãã³ãã¼ãã¦ã³ã¼ãèªã¿ã (define (searchâ¦
ãªãã®ã²ã¨ã¨ãå¿è ãã¼ã«ãå ¥ãã¦ã¿ã¾ããã
199, 1999, 19999ã®æå°é¤æ°ãæ±ãã (define (smallest-divisor n) (find-divisor n 2)) (define (find-divisor n test-divisor) (cond ((> (square test-divisor) n) n) ((divides? test-divisor n) test-divisor) (else (find-divisor n (+ test-divisor â¦
ã¡ãã£ã¨æ«æãã¾ãã...ä½åãããã°å¾ã§æ»ã£ã¦ããããã AnswerBookä¸å¿ãä½ç¨çé åºè©ä¾¡ã¯ãã£ã¦ã¿ãã ; ä½ç¨çé åºè©ä¾¡ (if (= 40 0) 206 (gcd 40 (remainder 206 40))) (if (= 40 0) 206 (if (= 6 0) 40 (gcd 40 (remainder 40 6)))) (if (= 40 0) 20â¦
é次平æ¹ã®å復çããã»ã¹ãã¼ã¸ã§ã³ãæ±ããçºæ³ã®è»¢æãå¿ è¦ã b^n = (b^(n/2))^2 = (b^2)^(n/2) b^n = b * b^(n-1) [æ®éã®é次平æ¹ãªãã°ãããªæã] 2^6 = (2^3)^2 = 8^2 = 8 * 8 = 64 [å復ããã»ã¹ã§è¡ããªãã°ãããã] 2^6 = (2^3)^2 = (2^2)^3 -->â¦
sinã®è¿ä¼¼ã¨å¢å éã®è¨ç® (define (cube x) (* x x x)) (define (p x) (- (* 3 x) (* 4 (cube x)))) (define (sine angle) (if (not (> (abs angle) 0.1)) angle (p (sine (/ angle 3.0))))) a. (sine 12.5) ã®è©ä¾¡ã§ãæç¶ãpã¯ä½åä½ç¨ããããããï¼5å (â¦
両æ¿åé¡ã¯é¢ç½ãã£ãã çå±ã¯åãããã©ã解ãã¦ãã¾ããã¨ããã£ã±ãä¸æè°ã ãã£ãããªã®ã§æ¥æ¬ç¡¬è²¨ã§ã®ä¸¡æ¿è¨ç®ãä½ã£ã¦ã¿ã¾ããã (define (count-change amount) (define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) (= kâ¦
æ¨æ§é ãæã§æ¸ãããã¼ãããã©ãã»ã»ã»ã ã§ãç·´ç¿ã«ã¯ã¡ããã©ãããã ; 11ã®å ´å (cc 11 5) (cc 11 4) (cc 11 3) (cc 11 2) (cc 11 1) (cc 11 0) -> 0 (cc 10 1) (cc 10 0) -> 0 (cc 9 1) (cc 9 0) -> 0 (cc 8 1) (cc 8 0) -> 0 (cc 7 1) (cc 7 0) -> 0â¦
Fib(n)ã Ï^n /â5 ã«æãè¿ãæ´æ°ã§ãããã¨ãã帰ç´æ³ãç¨ãã¦è¨¼æããã Ï = (1 + â5)/2 â 1.61803398874989 Ï^2 = Ï + 1 ããããé»éæ¯ã®ãã¨ã証æãªãã¦ä½å¹´ã¶ãã ãã...ãèªåã§è§£ãã®ã¯æ£ç´ç¡çã§ããm(__)mã AnswerBookãåçµããªãããèªåã®è¨â¦
Pascalä¸è§å½¢ãè¨ç®ããé¢æ°ãä½æããé¢æ°èªä½ã¯ç°¡åã«åºæ¥ãã ; 1ãnè¡, 1ãnå ç®ã®ãã¹ã«ã«ä¸è§å½¢ã®å¤ãè¿ã ; ç¯å²å¤ã®å ´åã¯0ãè¿ã (define (pascals-triangle row col) (cond ((> col row) 0) ((= col 1) 1) ((= row col) 1) (else (+ (pascals-triâ¦
ãã£ããããæ°è¨ç®ã®å¯¾æ°ã¹ãããçãä½ã çããè¦ãªãã証æãã¦ã¿ã¾ããããæ£ç´ç解ãããã¦ããªããªã...ã a = bq + aq + ap b = bp + aq a' = (bp + aq)q + (bq + aq + ap)q + (bq + aq + ap)p = bpq + aq^2 + bq^2 + aq^2 + apq + bpq + apq + ap^2â¦
1.17ã®å復ããã»ã¹çãä½ã (define (fast-mul2 a b) (define (iter a b total) (cond ((= b 0) total) ((even? b) (iter (double a) (halv b) total)) (else (iter a (- b 1) (+ total a))))) (iter a b 0)) (define (double x) (ash x 1)) (define (halv â¦
æãç®ãå²ãç®ã®ç¡ãä¸çã§ã足ãç®ã使ã£ã¦æãç®ãå®ç¾©ããé次平æ¹ã¯ã¹ãä¹ã®é«éåã ã£ããã ããã¯åããããªèãã§æãç®ãå®ç¾©ããããªãã¨ãªããdoubleã¨halvã¯ã·ããæ¼ç®ã§å®ç¾©ãã¦ã¿ãã (define (fast-mul a b) (cond ((= b 0) 0) ((even? b) (â¦
å帰é¢æ°ããå帰çããã»ã¹ãå復çããã»ã¹ã§è¨è¿°ãã ; çãåããç¨ã«ãã¬ã¼ã¹ ; (f 3) ; ==> (+ (f 2) (* 2 (f 1)) (* 3 (f 0))) ; ==> (+ 2 (* 2 1) (* 3 0)) ; ==> (+ 2 2 0) ; ==> 4 ; (f 4) ; ==> (+ (f 3) (* 2 (f 2)) (* 3 (f 1))) ; ==> (+ 4 4 â¦
Ackermanné¢æ°ã«ã¤ãã¦ããããAckermanné¢æ°ã£ã¦ãªãã ï¼ã£ã¦è©±ãªã®ã§ãWikipediaã§èª¿ã¹ã¦ã¿ãã ã¢ãã«ã¼ãã³é¢æ° - Wikipediaä»ã²ã¨ã¤åãããªãã®ã§å®éã«æ¸ãã¦åããã¦ã¿ãã (define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else â¦
ä¸è¨ã®2ã¤ã®æç¶ãããç½®ãæãã¢ãã«ãç¨ãã¦å³ç¤ºãã ãã®ããã»ã¹ã¯å復çãå帰çãï¼ ããã»ã¹ãå³ç¤ºãããã¨ã大åãããã»ã¹1 (plus 3 3) ==> (inc (plus 2 3)) ==> (inc (inc (plus 1 3))) ==> (inc (inc (inc (plus 0 3)))) ==> (inc (inc (inc 3))â¦
Meadowã§ã®run-guileã¢ã¼ãã¯ã¨ã¦ã便å©ãªãã ãã©ã ä½æ ãç¡éã«ã¼ãã«å ¥ãã¨C-cC-cãæ¼ãã¦ãæ¢ãããã¨ãåºæ¥ãªã...ãcygwinã ã¨ã guile> (load "question-1_9.scm") ERROR: User interrupt ABORT: (signal) ã¨ãã§åæ¢åºæ¥ããã ãã©ã run-guileã¢ã¼â¦
ç«æ¹æ ¹ãæ±ããæç¶ããä½æãã improveã®ã¿ãç«æ¹æ ¹ã®æç¶ãã«å¤æ´ããã°è¯ã ãã£ãããªã®ã§ãgood-enough?çã¯AnswerBook1.7ãåèã«ä½ããã¨ã«ãã å ±éé¢æ°ã¯å¥ãã¡ã¤ã«ã«ã¾ã¨ãããã¨ã«ãã(sicp-lib.scm - ãããããã®æ¥è¨) (load "sicp-lib.scm") â¦
1.1.7ç¯ã§ä½æãããsqrtã®å¼±ç¹ã解æãã ã¾ãããã®å¼±ç¹ãæ¹è¯ãã ã¨ãããããæ¤è¨¼ç¨æç¶ããä½ã (define (sqrt-test x) (/ (square (sqrt x)) x)) é常ã«å°ããæ°ã®å ´åãé¾å¤ãããå°ããæ°ã«ãªãã¨ç²¾åº¦ãæªããªãã å帰ãå°ãªãåæ°ã§çµäºãã¦ãã¾â¦
é常çã§ã¯ (sqrt 2) ==> 1.41421568627451 new-ifçã§ã¯ ==> ERROR: Stack overflow ==> ABORT: (stack-overflow) ifã§ã¯è¿°èªãtrueã«ãªããªãéãelseç¯ãè©ä¾¡ãããªããã new-ifã¯ãã ã®æç¶ãã®ãããå¼ã³åºããã¦ããã«thenç¯ãelseç¯ãè©ä¾¡ããã¦ãã¾â¦
(define (p) (p)) (define (test x y) (if (= x 0) 0 y)) ä½ç¨çé åºã®å ´å ç¡éã«ã¼ããã (test 0 (p)) => (test 0 (p)) => (test 0 (p (p (p) (p))))... æ£è¦é åºã®å ´å ã¾ãé¢æ°testãå±éãã (test x y) => (if (= x 0) 0 y) ;xãä»£å ¥ãã(yã¯ã¾ã ) =>â¦
ã¨ããããé¢æ°ãåããã¦ã¿ã¦ãã©ã®ãããªæ¯ãèããããã確ããã a-plus-abs-b 㯠a + abs(b) ã®ãã¨ã ã¨ãããã¨ã¯åããã°åããã (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)) (a-plus-abs-b 1 2) ; 3 (a-plus-abs-b 1 -2) ; 3 (a-plus-abs-â¦
XKeymacsãã¤ã³ã¹ãã¼ã«ã FireFoxãEmacsãã¼ãã¤ã³ãã§æä½ã§ããã¨ä¾¿å©ã ãªãã
Lispã¯æ¬å½ã«è²ã ãªå®è£ ããã£ã¦è¿·ãã æ®æ®µã¯Meadow+cygwinã§ããã°ã©ã ãã¦ããã®ã§ã試ãã«cygwin setupãè¦ãã¦ã¿ãããDevel/guile-develãçºè¦ã Meadowã¨ã®è¦ªåæ§ããããã®ãããã®ã§ãããã使ããã¨ã«ãid:higepon:20060415:1145108067ããã®è¨å®â¦
ä¸ã¤ã®æ°ãå¼æ°ã¨ãã¦åãã大ããäºã¤ã®æ°ã®äºä¹ã®åãè¿ãæç¶ããå®ç¾©ããã ããã¹ãã§åºã¦ãããsquare, sum-of-squaresã使ãã¾ãã ã½ã¼ãããå¿ è¦ã¯ç¡ããä¸çªå°ããæ°ãåããã°ãã (define (square x) (* x x)) ;(square 5) (define (sum-of-squaâ¦
次ã®å¼ãåç½®è¨æ³ã«ç¿»è¨³ãã ã¨ããããæ¸ãã¦ã¿ãã å®è¡ãã¦ã¿ã¦ãåããã¨ã確èªã åçéãè¦ã¦ãåãçããªãã¨ãç¢ºèª ç´°ãããã¨ã ãã©ãguileã¯æçæ°ã§åºåããã¦ãgaucheã¯å°æ°ã§åºåãããã®ã (/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2)â¦
å¼ã®åããããããããã®å¼ãå°åããçµæã¯ä½ããåã¯ç¤ºããé ã«è©ä¾¡ãããã®ã¨ããåé¡1.1ã¯ã¤ã³ã¿ããªã¿ã®ä½¿ãæ¹ãè¦ããã®ãã¡ã¤ã³ã åé¡ãæ£ããæã¡è¾¼ã¿ãçµæãèãè¨å ¥ãã¤ã³ã¿ããªã¿ã§çµæãçãåããã 10 ; 10 (+ 5 3 4) ; 12 (- 9 1) ; 8 (/ â¦