Skip to content

Instantly share code, notes, and snippets.

View manishym's full-sized avatar

Manish M Yathnalli manishym

View GitHub Profile
#include <stdio.h>
#include <stdint.h>
struct foo
{
char b;
__int128_t bar;
char baz;
__int128_t barz;
char barzz;
def decorator(d):
"""This is a decorator that will decorate all decorators. This will add update_wrapper
to all decorators.
(fun) -> fun
"""
def _d(f):
return update_wrapper(d(f), f)
return update_wrapper(_d, d)
[
{"keys": ["super+alt+ctrl+d"], "command": "add_date_time_stamp" },
{"keys": ["super+alt+d"], "command": "add_date_stamp" },
{"keys": ["super+alt+t"], "command": "add_time_stamp" }
]
@manishym
manishym / multiplication-using-addition.lisp
Created January 21, 2012 01:33
Multiplication using iterative addition
(defun double (n)
(+ n n))
(defun halve (n)
(/ n 2))
;;; Normal
(defun mul (a b)
(if (= b 1)
a
@manishym
manishym / iter-fast-expt.lisp
Created January 20, 2012 09:17
Iterative fast exponentiation
(defun fast-exponential-iter (b n)
(labels (
(iter (a x n)
;; x to the power of n, with a being accumulator
;; the number a * x^n should always be constant
;;(format t "~&A: ~A ~&X: ~A ~&N:~A ~&A*X^n: ~A" a x n (* a (expt x n)))
(cond ((= n 1) (* a x))
((evenp n) (iter a (square x) (/ n 2)))
(t (iter (* a x) x (- n 1))))))
(iter 1 b n)))
@manishym
manishym / crazy-function-iter-and-rec-performance.lisp
Created December 29, 2011 07:23
Crazy function performance
SICP3> (time ( crazy-func 30))
Evaluation took:
1.004 seconds of real time
0.996835 seconds of total run time (0.995984 user, 0.000851 system)
99.30% CPU
2,263,991,379 processor cycles
496 bytes consed
61354575194
SICP3> (time ( crazy-func-iter 30))
@manishym
manishym / crazy-function-iter-and-rec.lisp
Created December 29, 2011 07:19
Converting tree recursive process into iterative process
(defun crazy-func (n)
(cond ((< n 3) n)
(t (+ (crazy-func (- n 1))
(* 2 (crazy-func (- n 2) ))
(* 3 (crazy-func (- n 3)))))))
(defun crazy-func-iter (n)
(crazy-iter 2 1 0 3 n))
;;; iter alogrithm:
@manishym
manishym / count-change-recursive.lisp
Created December 26, 2011 04:07
Counting change recursive
(defun count-change (amount)
(labels (
(count-change-rec (amt coins)
(cond ((= amt 0) 1)
((single? coins) 1)
((< amt 0) 0)
(t (+ (count-change-rec amt (rest coins))
(count-change-rec (- amt (first coins)) coins))))))
(count-change-rec amount coins)))
@manishym
manishym / performance-fiboncci-loop.lisp
Created December 25, 2011 06:04
Performance of iterative and loop versions of fibonacci
SICP3> (time (fib-iter 10000))
Evaluation took:
0.011 seconds of real time
0.005020 seconds of total run time (0.004394 user, 0.000626 system)
45.45% CPU
24,709,407 processor cycles
4,575,696 bytes consed
33644764876431783266621612005107543310302148460680063906564769974680081442166662368155595513633734025582065332680836159373734790483865268263040892463056431887354544369559827491606602099884183933864652731300088830269235673613135117579297437854413752130520504347701602264758318906527890855154366159582987279682987510631200575428783453215515103870818298969791613127856265033195487140214287532698187962046936097879900350962302291026368131493195275630227837628441540360584402572114334961180023091208287046088923962328835461505776583271252546093591128203925285393434620904245248929403901706233888991085841065183173360437470737908552631764325733993712871937587746897479926305837065742830161637408969178426378624212835258112820516370298089332099905707920064367426202389783111470054074998459250360633560933883831923
@manishym
manishym / fibonacci-iteration-loop.lisp
Created December 25, 2011 06:02
Fibonacci in lisp - iteration - loop
(defun fib-loop (num)
(do ((n 0 (1+ n))
(cur 0 next)
(next 1 (+ cur next)))
((= num n) cur)))