asb: head /dev/brain > /dev/www

My home, musings, and wanderings on the world wide web.

99 LISP problems: Problem #34

Solution to the 99 LISP Problems #34

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(defun range (lo hi)
    (cond ((> lo hi) nil)
    (t (cons lo (range (1+ lo) hi)))))

(defun eucgcd (m n)
    (let ((p (abs m)) (q (abs n)))
        (cond ((= m n) m)
        (t (gcd (- (max m n) (min m n)) (min m n))))))

(defun coprimep (m n)
    (= (eucgcd m n) 1))

(defun totient (m)
  (cond ((= m 1) 1)
        (t (apply #'+ (mapcar
                        (lambda (x) (if (coprimep m x) 1 0))
                        (range 1 (1- m)))))))

Lisp dialect: Steel Bank Common Lisp

99 LISP problems: Problem #31

Solution to the 99 LISP Problems #31

1
2
3
4
5
6
7
8
9
10
11
12
13
(defun range (lo hi)
  (cond ((> lo hi) nil)
        (t (cons lo (range (1+ lo) hi)))))

(defun all (alist)
  (cond ((null alist) t)
        (t (and (car alist)
                (all (cdr alist))))))

(defun primep (n)
  (all (mapcar
         (lambda (x) (not (= 0 (mod n x))))
         (range 2 (isqrt n)))))

Lisp dialect: Steel Bank Common Lisp

Julia - Project Euler Qs 1 - 10

So, today I decided to take Julia for a spin because, finally, it has a stable version available in the Arch community repo. I tried it with the Project Euler problems to get started. Here is a bunch of code in Julia that solves problems 1 - 10 of Project Euler. I have been watching a lot of videos on the language. I will probably follow up with a post on initial thoughts about the language.