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
; 迭代式改进. -- 哈哈哈. 最终的社区精简版, 竟然是我这种写法. --- 编程理念的差异. 在可读性和技巧性的取舍上, 我优先选择 可读性. | |
(define (iterative-improve good-enough? impove) | |
(define (f x) | |
(if (good-enough? x) | |
x | |
(f (impove x)) | |
) | |
) | |
f | |
) |
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
// mirror... | |
func cons<T0, T1>(_ x: T0, _ y: T1) -> (T0, T1) { | |
return (x, y) | |
} | |
func car<T0, T1>(_ t:(T0, T1)) -> T0 { | |
return t.0 | |
} | |
func cdr<T0, T1>(_ t:(T0, T1)) -> T1 { |
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
(define (my-cons x y) | |
(lambda (m) | |
(cond ((= m 0) x) | |
((= m 1) y))) | |
) | |
(define (my-car z) (z 0)) | |
(define (my-cdr z) (z 1)) |
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
(define zero (lambda (f) (lambda (x) x))) | |
(define one (lambda (f) (lambda (x) (f x)))) | |
(define two (lambda (f) (lambda (x) (f (f x))))) | |
(define three (lambda (f) (lambda (x) (f (f (f x)))))) | |
(define (add m n) | |
(lambda (f) (lambda (x) ((m f) ((n f) x)))) |
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
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.In; | |
import edu.princeton.cs.algs4.StdOut; | |
import java.util.Arrays; | |
import java.util.Random; | |
import java.util.concurrent.ThreadLocalRandom; | |
// for 1.1.39 |
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
; (define (mul-interval x y) | |
; (let ((p1 (* (lower-bound x) (lower-bound y))) | |
; (p2 (* (lower-bound x) (upper-bound y))) | |
; (p3 (* (upper-bound x) (lower-bound y))) | |
; (p4 (* (upper-bound x) (upper-bound y))) | |
; ) | |
; (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)) | |
; ) | |
; ) |
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.14.scm 中有一部分. | |
; 既有实现的输出: 4. | |
(count-change 10) | |
; 新的实现... | |
(define us-coins (list 50 25 10 5 1)) | |
(define us-coins-0 (list 1 5 10 25 50)) | |
(define us-coins-1 (list 50 5 10 1 25)) | |
(define uk-coins (list 100 50 20 10 5 2 1 0.5)) |
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
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
public class SmartDate { | |
private final int month; | |
private final int day; | |
private final int year; | |
public SmartDate(int m, int d, int y) throws RuntimeException | |
{ |
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
; 基础方法 | |
(define (same-parity x . l) | |
(same-parity-adpater x l) | |
) | |
(define (same-parity-adpater x l) | |
(if (null? l) | |
(cons x l) | |
(let ((car-item (car l))) | |
(if (even? (+ car-item x)) |
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
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
public class SmartDate { | |
private final int month; | |
private final int day; | |
private final int year; | |
public SmartDate(int m, int d, int y) throws RuntimeException | |
{ |