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.139 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.138 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.137 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.136 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.135 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.134 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.133 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.132 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.131 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.130 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.129 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.128 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.127 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.126 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.125 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.124 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.123 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.122 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.121 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.120 tracks/common-lisp/exercises/collatz-conjecture/example.lisp