mirror of
https://github.com/ossu/computer-science.git
synced 2026-04-11 14:21:57 +08:00
Finnished systemic design
This commit is contained in:
parent
e7444295ae
commit
e5c53bf2c2
BIN
completedwork/core_programming/01_systemic_design/#fs-starter.rkt#2#
Executable file
BIN
completedwork/core_programming/01_systemic_design/#fs-starter.rkt#2#
Executable file
Binary file not shown.
BIN
completedwork/core_programming/01_systemic_design/.DS_Store
vendored
Normal file
BIN
completedwork/core_programming/01_systemic_design/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
completedwork/core_programming/01_systemic_design/10 - Accumulators/.DS_Store
vendored
Normal file
BIN
completedwork/core_programming/01_systemic_design/10 - Accumulators/.DS_Store
vendored
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,70 @@
|
||||
;; The first three lines of this file were inserted by DrRacket. They record metadata
|
||||
;; about the language level of this file in a form that our tools can easily process.
|
||||
#reader(lib "htdp-advanced-reader.ss" "lang")((modname count-odd-even-solution) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f)))
|
||||
|
||||
;; count-odd-even-solution.rkt
|
||||
|
||||
; PROBLEM:
|
||||
;
|
||||
; Previously we have written functions to count the number of elements in a list. In this
|
||||
; problem we want a function that produces separate counts of the number of odd and even
|
||||
; numbers in a list, and we only want to traverse the list once to produce that result.
|
||||
;
|
||||
; Design a tail recursive function that produces the Counts for a given list of numbers.
|
||||
; Your function should produce Counts, as defined by the data definition below.
|
||||
;
|
||||
; There are two ways to code this function, one with 2 accumulators and one with a single
|
||||
; accumulator. You should provide both solutions.
|
||||
;
|
||||
|
||||
|
||||
(define-struct counts (odds evens))
|
||||
;; Counts is (make-counts Natural Natural)
|
||||
;; interp. describes the number of even and odd numbers in a list
|
||||
|
||||
(define C1 (make-counts 0 0)) ;describes an empty list
|
||||
(define C2 (make-counts 3 2)) ;describes (list 1 2 3 4 5))
|
||||
|
||||
|
||||
;; (listof Integer) -> Counts
|
||||
;; Produce the count of odd and even numbers in lon
|
||||
|
||||
(check-expect (count empty) (make-counts 0 0))
|
||||
(check-expect (count (list 1)) (make-counts 1 0))
|
||||
(check-expect (count (list 2)) (make-counts 0 1))
|
||||
(check-expect (count (list 1 2 3 4 5)) (make-counts 3 2))
|
||||
(check-expect (count (list -1 -2 3 -4 5)) (make-counts 3 2))
|
||||
|
||||
|
||||
; <template according to (listof Number) + 2 accumulators>
|
||||
(define (count lon0)
|
||||
;; odds: Natural; the count of odd numbers so far
|
||||
;; evens: Natural; the count of even numbers so far
|
||||
;;
|
||||
;; (count (list 1 2 3) 0 0)
|
||||
;; (count (list 2 3) 1 0)
|
||||
;; (count (list 3) 1 1)
|
||||
;; (count empty 2 1)
|
||||
(local [(define (count lon odds evens)
|
||||
(cond [(empty? lon)(make-counts odds evens)]
|
||||
[else
|
||||
(if (odd? (first lon))
|
||||
(count (rest lon) (add1 odds) evens)
|
||||
(count (rest lon) odds (add1 evens)))]))]
|
||||
(count lon0 0 0)))
|
||||
|
||||
#;
|
||||
; <template according to (listof Number) + accumulator>
|
||||
(define (count lon0)
|
||||
;; rsf: Count; the counts so far
|
||||
;; (count (list 1 2 3) (make-counts 0 0))
|
||||
;; (count (list 2 3) (make-counts 1 0))
|
||||
;; (count (list 3) (make-counts 1 1))
|
||||
;; (count empty (make-counts 2 1))
|
||||
(local [(define (count lon rsf)
|
||||
(cond [(empty? lon) rsf]
|
||||
[else
|
||||
(if (odd? (first lon))
|
||||
(count (rest lon) (make-counts (add1 (counts-odds rsf)) (counts-evens rsf)))
|
||||
(count (rest lon) (make-counts (counts-odds rsf) (add1 (counts-evens rsf)))))]))]
|
||||
(count lon0 (make-counts 0 0))))
|
||||
@ -0,0 +1,55 @@
|
||||
;; The first three lines of this file were inserted by DrRacket. They record metadata
|
||||
;; about the language level of this file in a form that our tools can easily process.
|
||||
#reader(lib "htdp-advanced-reader.ss" "lang")((modname count-odd-even-starter) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #t #t none #f () #f)))
|
||||
|
||||
;; count-odd-even-starter.rkt
|
||||
|
||||
; PROBLEM:
|
||||
;
|
||||
; Previously we have written functions to count the number
|
||||
;of elements in a list. In this
|
||||
; problem we want a function that produces separate
|
||||
;counts of the number of odd and even
|
||||
; numbers in a list, and we only want to traverse
|
||||
;the list once to produce that result.
|
||||
;
|
||||
; Design a tail recursive function that produces
|
||||
;the Counts for a given list of numbers.
|
||||
; Your function should produce Counts, as defined
|
||||
;by the data definition below.
|
||||
;
|
||||
; There are two ways to code this function,
|
||||
;one with 2 accumulators and one with a single
|
||||
; accumulator. You should provide both solutions.
|
||||
;
|
||||
|
||||
|
||||
(define-struct counts (odds evens))
|
||||
;; Counts is (make-counts Natural Natural)
|
||||
;; interp. describes the number of even and odd numbers in a list
|
||||
|
||||
(define C1 (make-counts 0 0)) ;describes an empty list
|
||||
(define C2 (make-counts 3 2)) ;describes (list 1 2 3 4 5))
|
||||
|
||||
(check-expect (count empty) (make-counts 0 0))
|
||||
(check-expect (count (list 1)) (make-counts 1 0))
|
||||
(check-expect (count (list 2)) (make-counts 0 1))
|
||||
(check-expect (count (list 1 2 3 4 5)) (make-counts 3 2))
|
||||
(check-expect (count (list -1 -2 3 -4 5)) (make-counts 3 2))
|
||||
|
||||
(define (count1 lon acc)
|
||||
(cond [(empty? lon) acc]
|
||||
[(odd? (first lon))
|
||||
(count1 (rest lon) (make-counts (add1 (counts-odds acc))
|
||||
(counts-evens acc)))]
|
||||
[(even? (first lon))
|
||||
(count1 (rest lon) (make-counts (counts-odds acc)
|
||||
(add1 (counts-evens acc))))]))
|
||||
|
||||
(define (count2 lon odds evens)
|
||||
(cond [(empty? lon) (make-counts odds evens)]
|
||||
[(odd? (first lon)) (count2 (rest lon) (add1 odds) evens)]
|
||||
[(even? (first lon)) (count2 (rest lon) odds (add1 evens))]))
|
||||
|
||||
(define (count lon) (count1 lon (make-counts 0 0)))
|
||||
;(define (count lon) (count2 lon 0 0))
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
BIN
completedwork/core_programming/01_systemic_design/11 - Graphs/.DS_Store
vendored
Normal file
BIN
completedwork/core_programming/01_systemic_design/11 - Graphs/.DS_Store
vendored
Normal file
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -0,0 +1,46 @@
|
||||
(define H4
|
||||
(shared ((-A- (make-room "A" (list -B- -D-)))
|
||||
(-B- (make-room "B" (list -C- -E-)))
|
||||
(-C- (make-room "C" (list -B-)))
|
||||
(-D- (make-room "D" (list -E-)))
|
||||
(-E- (make-room "E" (list -F- -A-)))
|
||||
(-F- (make-room "F" (list))))
|
||||
-A-))
|
||||
|
||||
Start with:
|
||||
|
||||
room exits to
|
||||
---- --------
|
||||
A B D
|
||||
B C E
|
||||
C B
|
||||
D E
|
||||
E F A
|
||||
F NOTHING
|
||||
|
||||
we need function like template, but add another thing
|
||||
(room, number-of-exits-TO-this-room): (Room, Natural)
|
||||
|
||||
fn-for-room is like:
|
||||
(fn-for-room room todo visited list-of-rooms-and-number-of-exits-TO-them)
|
||||
|
||||
we start with fn-for-room A empty empty empty
|
||||
Then we keep updating...
|
||||
|
||||
function room todo visited counts
|
||||
fn-for-room A empty empty empty
|
||||
fn-for-lor _ B,D A (B,1),(D,1)
|
||||
fn-for-room B D A (B,1),(D,1)
|
||||
fn-for-lor _ D,C,E A,B (B,1),(D,1),(C,1),(E,1)
|
||||
fn-for-room D C,E A,B (B,1),(D,1),(C,1),(E,1)
|
||||
fn-for-lor _ C,E A,B,D (B,1),(D,1),(C,1),(E,2)
|
||||
fn-for-room C E A,B,D (B,1),(D,1),(C,1),(E,2)
|
||||
fn-for-lor _ E A,B,D,C (B,2),(D,1),(C,1),(E,2)
|
||||
fn-for-room E empty A,B,D,C (B,2),(D,1),(C,1),(E,2)
|
||||
fn-for-lor _ F A,B,C,D,E (B,2),(D,1),(C,1),(E,2),(F,1),(A,1)
|
||||
fn-for-room F empty A,B,D,C,E (B,2),(D,1),(C,1),(E,2),(F,1),(A,1)
|
||||
fn-for-lor _ empty A,B,C,D,E,F (B,2),(D,1),(C,1),(E,2),(F,1),(A,1)
|
||||
|
||||
Then take this output
|
||||
(B,2),(D,1),(C,1),(E,2),(F,1),(A,1)
|
||||
and pick room with max exits TO it (either B or E)
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -0,0 +1,18 @@
|
||||
;; The first three lines of this file were inserted by DrRacket. They record metadata
|
||||
;; about the language level of this file in a form that our tools can easily process.
|
||||
#reader(lib "htdp-beginner-reader.ss" "lang")((modname function-definitions-starter) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
|
||||
(require 2htdp/image)
|
||||
|
||||
;; function-definitions-starter.rkt
|
||||
|
||||
;(above (circle 40 "solid" "red")
|
||||
; (circle 40 "solid" "yellow")
|
||||
; (circle 40 "solid" "green"))
|
||||
|
||||
(define (bulb c)
|
||||
(circle 40 "solid" c))
|
||||
|
||||
(above (bulb "red")
|
||||
(bulb "yellow")
|
||||
(bulb "green"))
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
BIN
completedwork/core_programming/01_systemic_design/1a - BSL/pythag-starter.rkt
Executable file
BIN
completedwork/core_programming/01_systemic_design/1a - BSL/pythag-starter.rkt
Executable file
Binary file not shown.
2126
completedwork/core_programming/01_systemic_design/1a - BSL/tile-solution.rkt
Executable file
2126
completedwork/core_programming/01_systemic_design/1a - BSL/tile-solution.rkt
Executable file
File diff suppressed because it is too large
Load Diff
2079
completedwork/core_programming/01_systemic_design/1a - BSL/tile-starter.rkt
Executable file
2079
completedwork/core_programming/01_systemic_design/1a - BSL/tile-starter.rkt
Executable file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
2404
completedwork/core_programming/01_systemic_design/1b - HtDF/boxify-solution.rkt
Executable file
2404
completedwork/core_programming/01_systemic_design/1b - HtDF/boxify-solution.rkt
Executable file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user