Sha256: 07707d24a4493ef9ee10beed7636f081fc4f89f9f173b37c4722e3be6b5e9040

Contents?: true

Size: 346 Bytes

Versions: 145

Compression:

Stored size: 346 Bytes

Contents

(defpackage #:collatz-conjecture
  (:use #:common-lisp)
  (:export #:collatz))

(in-package #:collatz-conjecture)

(defun collatz-helper (a n)
  (cond ((= n 1)   a)
        ((evenp n) (collatz-helper (+ 1 a) (floor n 2)))
        (T         (collatz-helper (+ 1 a) (+ 1 (* 3 n))))))

(defun collatz (n)
  (when (> n 0)
    (collatz-helper 0 n)))

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.179 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.178 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.177 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.176 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.175 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.174 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.173 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.172 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.171 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.170 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.169 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.167 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.166 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.165 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.164 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.163 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.162 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.161 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.160 tracks/common-lisp/exercises/collatz-conjecture/example.lisp