Sha256: fbe020bb3c3f77280118a63a81811bb215b1294ff4629cf1de1cef95612098da

Contents?: true

Size: 402 Bytes

Versions: 131

Compression:

Stored size: 402 Bytes

Contents

#lang racket

(provide collatz)

(define (collatz-length n [acc 0])
  (if (= n 1)
      acc
      (collatz-length (if (even? n)
                          (/ n 2)
                          (add1 (* 3 n)))
                      (add1 acc))))

(define (collatz n)
  (if (nand (exact-integer? n)
            (positive? n))
      (error "number must be a positive integer")
      (collatz-length n)))
  

  

Version data entries

131 entries across 131 versions & 1 rubygems

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