Skip to content

Instantly share code, notes, and snippets.

View mohanrajendran's full-sized avatar

Mohan Rajendran mohanrajendran

View GitHub Profile
@mohanrajendran
mohanrajendran / gcloud-fastai.sh
Last active March 7, 2018 20:36
Script to set up a deep learning box for fast.ai MOOC on Google cloud
# This script is designed to work with ubuntu 16.04 LTS
# ensure system is updated and has basic build tools
sudo apt-get update
sudo apt-get --assume-yes upgrade
sudo apt-get --assume-yes install tmux build-essential gcc g++ make binutils git
sudo apt-get --assume-yes install software-properties-common
# download and install GPU drivers
wget "http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.44-1_amd64.deb" -O "cuda-repo-ubuntu1604_8.0.44-1_amd64.deb"
@mohanrajendran
mohanrajendran / Chapter3_3_1.rkt
Created November 15, 2015 20:13
SICP Working Code
#lang planet neil/sicp
(define (append x y)
(if (null? x)
y
(cons (car x) (append (cdr x) y))))
(define (last-pair x)
(if (null? (cdr x))
x
@mohanrajendran
mohanrajendran / 113plot.py
Last active August 29, 2015 14:04
SICP Exercise 1.14 Plotting
import pygraphviz as pgv
import networkx as nx
nodeCount = 1
G = nx.DiGraph()
Ranks = {}
def countChange(amount):
global G
global Ranks
@mohanrajendran
mohanrajendran / Exercise1-12.scm
Created July 14, 2014 02:46
SICP Exercise 1.12
;; Rows and columns start with index 1
(define (pascal row col)
(cond ((or (= col 1) (= col row)) 1)
(else (+ (pascal (- row 1) col) (pascal (- row 1) (- col 1))))))
;; Test cases
(pascal 1 1)
; 1
(pascal 13 7)
; 924
@mohanrajendran
mohanrajendran / Exercise1-11.scm
Created July 13, 2014 22:37
SICP Exercise 1.11
;;; Original function
(define (f n)
(cond ((< n 3) n)
(else (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)))))))
; f
(f 0)
; 0
(f 1)
; 1
@mohanrajendran
mohanrajendran / Exercise1-10.md
Created July 13, 2014 21:56
SICP Exercise 1.10

The following are the results from defining and evaluating the Ackermann's function on various arguments.

(define (A x y)
  (cond ((= y 0) 0)
  	((= x 0) (* 2 y))
	((= y 1) 2)
	(else (A (- x 1)
	      	 (A x (- y 1))))))
; A
@mohanrajendran
mohanrajendran / Exercise1-9.md
Created July 11, 2014 00:28
SICP Exercise 1.9

Expansion of (+ 4 5) using first definition

(define (+ a b)
  (if (= a 0)
      b
      (inc (+ (dec a) b))))

(+ 4 5)
(inc (+ (dec 4) 5))
@mohanrajendran
mohanrajendran / Exercise1-8.scm
Created July 9, 2014 12:41
SICP Exercise 1.8
(define (cbrt-iter guess prev-guess x)
(if (good-enough? guess prev-guess)
guess
(sqrt-iter (improve guess x)
guess
x)))
; cbrt-iter
(define (improve guess x)
(/ (+ (/ x (square guess)) (* 2 guess)) 3))
@mohanrajendran
mohanrajendran / Exercise1-7.md
Last active August 29, 2015 14:03
SICP Exercise 1.7

The good-enough? function is not so effective when we use small numbers as arguments in the function.

For example, when we want to find the square root of 0.0001 which is 0.01,

(sqrt 0.0001)

;.03230844833048122
@mohanrajendran
mohanrajendran / Exercise1-6.md
Last active August 29, 2015 14:03
SICP Exercise 1.6
(define (new-if predicate then-clause else-clause)
  (cond (predicate then-clause)
        (else else-clause)))

(define (sqrt-iter guess x)
  (new-if (good-enough? guess x)
          guess
          (sqrt-iter (improve guess x)
 x)))