Giter VIP home page Giter VIP logo

sicp-racket-basic's Introduction

SICP-racket-basic

The Racket language is a modern dialect of Lisp and a descendant of the Scheme. It is designed as a platform for programming language design and implementation.

language-racket-andremayer

Basic racket programs of SICP course

  1. Factorial Recursive.rkt
#lang racket
(define (factorial n)
   (if (= n 1)
     1
      (* n (factorial (- n 1))))) 
  1. Factorial Iterative.rkt
#lang racket
(define (fact-iter product counter max-count)
   (if (> counter max-count)
        product
        (fact-iter (* counter product)
                       (+ counter 1)
                       max-count)
    )
)
(define (factorial n)
(fact-iter 1 1 n))
  1. Fibonacci Tree Recursive.rkt
#lang racket
(define (fib n)
   (cond ( (= n 0) 0)
             ( (= n 1) 1)
             (else ( + (fib (-  n 1))
                            (fib (- n 2))
                      )
              )
    )
)
  1. Fibonacci Iterative.rkt
#lang racket
(define (fib-iter a b count)
   (if (= count 0)
        b
        (fib-iter (+ a b) a (- count 1))))
(define (fib n)
(fib-iter 1 0 n))
  1. Exponential Recursive.rkt
#lang racket
(define (expt b n)
   
   (if (= n 0)
        1
        (* b (expt b (- n 1)))))
        
  1. Exponential Iterative.rkt
#lang racket
(define (expt-iter b counter product)
   (if (= counter 0)
        product
        (expt-iter b 
                        (- counter 1)
                        (* b product))))

(define (expt b n)
   (expt-iter b n 1))
  1. Fast Exponential.rkt
#lang racket
(define (even? n) (= (remainder n 2)  0))

(define (square n) (* n n))

(define (fast-expt b n)
   (cond ((= n 0) 1)
             ((even? n) (square (fast-expt b (/ n 2))))
             (else (* b (fast-expt b (- n 1))))))
             
  1. GCD Recursive.rkt
#lang racket
(define (gcd a b)
(if (= b 0)
   a
   (gcd b (remainder a b))))

sicp-racket-basic's People

Contributors

guhankesav avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.