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.119 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.118 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.117 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.116 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.115 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.114 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.113 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.111 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.110 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.109 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.108 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.107 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.106 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.105 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.104 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.103 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.102 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.101 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.100 tracks/common-lisp/exercises/collatz-conjecture/example.lisp
trackler-2.2.1.99 tracks/common-lisp/exercises/collatz-conjecture/example.lisp