Skip to content

Instantly share code, notes, and snippets.

View thinkphp's full-sized avatar
💭
If I have seen further it is only by standing on the shoulders of giants. Newton

Adrian Statescu thinkphp

💭
If I have seen further it is only by standing on the shoulders of giants. Newton
View GitHub Profile
@thinkphp
thinkphp / gist:5348581
Last active April 11, 2023 08:06
Test if a number is prime or not in Common LISP.
;Test if a number is prime or NOT.
;Adrian Statescu <mergesortv@gmail.com>
;License
;MIT
;Cheers!
(defun forall(L P)
(if (null L)
T
(and (FUNCALL P (cAR L)) (forall (CDR L) P) )
@thinkphp
thinkphp / gist:5431087
Last active December 16, 2015 11:59
Project Euler Problem 3 in Common Lisp
;Project Euler Problem 3
;Largest prime factor
;The prime factors of 13195 are 5, 7, 13 and 29.
;What is the largest prime factor of the number 600851475143 ?
(defun largest (N)
(setf i 2)
(prog (fac)
start
(if (<= (* i i) N)
@thinkphp
thinkphp / gist:5487441
Last active December 16, 2015 19:49
Sorting a list using Binary Search Tree Traversal Inorder in Common Lisp
; http://thinkphp.ro
; Adrian Statescu <mergesortv@gmail.com>
;
; Sorting a list using Binary Search Tree Traversal Inorder in Common Lisp
;
; License
; MIT
;
; 9
; 3
@thinkphp
thinkphp / gist:5531975
Created May 7, 2013 11:33
to count off a list (a b c) -> ((1 a) (2 b) (3 c))
;To Count Off a List
;Adrian Statescu <mergesortv@gmail.com>
;solution using mapcar
(defun countoff (L &aux (c 0))
(mapcar #'(lambda (x)(list (setf c (+ c 1)) x) ) L)
)
@thinkphp
thinkphp / gist:5539631
Last active December 17, 2015 02:59
Compare factorials iterative vs recursive plus (allfact '(1 2 3)) -> (1 2 6) in Common Lisp
;Adrian Statescu <thinkphp.ro>
;compare factorial written recursively with factorial written iteratively with prog
;i.e. 52!
;recursive
(defun factorial (n)
(if (= n 1)
1
@thinkphp
thinkphp / gist:5586924
Last active December 17, 2015 09:19
I/O File Common Lisp
(load 'filename print T)
@thinkphp
thinkphp / gist:5657329
Last active December 17, 2015 18:59
Calculating prime factors in Common Lisp
;Adrian Statescu <mergesortv@gmail.com>
;(factors 8)
;(2 3)
(defun factors (N)
(let ((R))
(do ((x N)(c 0)(i 2 (+ i 1))) ((= x 1) R)
(setf c 0)
@thinkphp
thinkphp / gist:5665949
Created May 28, 2013 20:41
Decomposition in prime factors in Python
#
# Decomposition in prime factors
# 10 = 2^2 * 5^2
#
import sys
def factors(n):
i = 2
@thinkphp
thinkphp / gist:5669206
Created May 29, 2013 09:52
Converts a decimal to binar in Common Lisp
;Adrian Statescu <mergesortv@gmail.com>
;converts a decimal to binar
(defun toBin(N)
+
+ (let ((R))
+
+ (dotimes (i 15 R)
+
+ (setf bit (logand (ash N (- i)) 1))
+
@thinkphp
thinkphp / gist:5e85d98960220f8a88f3
Created September 12, 2014 09:57
A dead simple ruby that generates a file.out with randomly integers between LI and LS without duplicates.
class Generate
def initialize(filename)
@filename = filename
end
def between(num, li, ls)