How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Clojure programming language
Table of Contents
Problem Statement
Using the in-built capabilities of your language, calculate the integer value of:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Arbitrary-precision integers (included) step by step in the Clojure programming language
Source code in the clojure programming language
(defn exp [n k] (reduce * (repeat k n)))
(def big (->> 2 (exp 3) (exp 4) (exp 5)))
(def sbig (str big))
(assert (= "62060698786608744707" (.substring sbig 0 20)))
(assert (= "92256259918212890625" (.substring sbig (- (count sbig) 20))))
(println (count sbig) "digits")
(println (str (.substring sbig 0 20) ".."
(.substring sbig (- (count sbig) 20)))
(str "(" (count sbig) " digits)"))
(defn exp [n k]
(cond
(zero? (mod k 2)) (recur (* n n) (/ k 2))
(zero? (mod k 3)) (recur (* n n n) (/ k 3))
:else (reduce * (repeat k n))))
You may also check:How to resolve the algorithm Bifid cipher step by step in the Perl programming language
You may also check:How to resolve the algorithm First-class functions step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Klong programming language
You may also check:How to resolve the algorithm Tau number step by step in the Nim programming language
You may also check:How to resolve the algorithm N'th step by step in the Arturo programming language