Add more examples
This commit is contained in:
parent
5d17aa3655
commit
9ded988259
104
.gitignore
vendored
104
.gitignore
vendored
@ -1,51 +1,52 @@
|
||||
# ---> VisualStudioCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
# Created by https://www.gitignore.io/api/macos,scheme,jetbrains+all,visualstudiocode
|
||||
# Edit at https://www.gitignore.io/?templates=macos,scheme,jetbrains+all,visualstudiocode
|
||||
|
||||
# ---> Scheme
|
||||
*.ss~
|
||||
*.ss#*
|
||||
.#*.ss
|
||||
|
||||
*.scm~
|
||||
*.scm#*
|
||||
.#*.scm
|
||||
|
||||
# ---> JetBrains
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
||||
### JetBrains+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff:
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/dictionaries
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.xml
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle:
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
@ -62,15 +63,37 @@ crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# ---> macOS
|
||||
*.DS_Store
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### JetBrains+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
@ -90,3 +113,24 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Scheme ###
|
||||
*.ss~
|
||||
*.ss#*
|
||||
.#*.ss
|
||||
|
||||
*.scm~
|
||||
*.scm#*
|
||||
.#*.scm
|
||||
|
||||
### VisualStudioCode ###
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
### VisualStudioCode Patch ###
|
||||
# Ignore all local history of files
|
||||
.history
|
||||
|
||||
# End of https://www.gitignore.io/api/macos,scheme,jetbrains+all,visualstudiocode
|
||||
|
58
lib.scm
58
lib.scm
@ -1,6 +1,11 @@
|
||||
(define (sqrt x)
|
||||
#lang sicp
|
||||
(define (average x y) (/ (+ x y) 2))
|
||||
(define (square x) (* x x))
|
||||
(define (cube x) (* x x x))
|
||||
(define (% a b)
|
||||
(remainder a b))
|
||||
|
||||
(define (sqrt x)
|
||||
(define (good-enough? guess)
|
||||
(< (abs (- (square guess) x)) 0.00001))
|
||||
(define (improve guess)
|
||||
@ -21,7 +26,6 @@
|
||||
(fact-iter (* counter product)
|
||||
(+ counter 1)
|
||||
max-count)))
|
||||
|
||||
(fact-iter 1 1 n))
|
||||
|
||||
|
||||
@ -64,7 +68,6 @@
|
||||
(+ (cc amount (- kinds-of-coins 1))
|
||||
(cc (- amount (first-denomination kinds-of-coins))
|
||||
kinds-of-coins)))))
|
||||
|
||||
(cc amount 5))
|
||||
|
||||
|
||||
@ -74,3 +77,52 @@
|
||||
(ptri (- n 1))
|
||||
(+ (* (ptri (- n 2)) 2)
|
||||
(* (ptri (- n 3)) 3)))))
|
||||
|
||||
|
||||
(define (p x) (- (* 3 x) (* 4 (cube x))))
|
||||
(define (sine angle)
|
||||
(if (not (> (abs angle) 0.1))
|
||||
angle
|
||||
(p (sine (/ angle 3.0)))))
|
||||
|
||||
;(define (expt b n)
|
||||
; (if (= n 0) 1 (* b (expt b (- n 1)))))
|
||||
|
||||
(define (expt b n) (expt-iter b n 1))
|
||||
(define (expt-iter b counter product)
|
||||
(if (= counter 0)
|
||||
product
|
||||
(expt-iter b
|
||||
(- counter 1)
|
||||
(* b product))))
|
||||
|
||||
(define (fast-exp b n)
|
||||
(cond ((= n 0)
|
||||
1)
|
||||
((even? n)
|
||||
(square (fast-exp b (/ n 2))))
|
||||
(else
|
||||
(* b (fast-exp b (- n 1))))))
|
||||
|
||||
(define (gcd a b)
|
||||
(if (= b 0)
|
||||
a
|
||||
(gcd b (% a b))))
|
||||
|
||||
(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 1)))))
|
||||
|
||||
(define (divides? a b)
|
||||
(= (% b a) 0))
|
||||
|
||||
(define (prime? n)
|
||||
(= n (smallest-divisor n)))
|
Loading…
Reference in New Issue
Block a user