How to resolve the algorithm Tau number step by step in the Clojure programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Tau number step by step in the Clojure programming language
Table of Contents
Problem Statement
A Tau number is a positive integer divisible by the count of its positive divisors.
Show the first 100 Tau numbers. The numbers shall be generated during run-time (i.e. the code may not contain string literals, sets/arrays of integers, or alike).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Tau number step by step in the Clojure programming language
Source code in the clojure programming language
(require '[clojure.string :refer [join]])
(require '[clojure.pprint :refer [cl-format]])
(defn divisors [n] (filter #(zero? (rem n %)) (range 1 (inc n))))
(defn display-results [label per-line width nums]
(doall (map println (cons (str "\n" label ":") (list
(join "\n" (map #(join " " %)
(partition-all per-line (map #(cl-format nil "~v:d" width %) nums)))))))))
(display-results "Tau function - first 100" 20 3
(take 100 (map (comp count divisors) (drop 1 (range)))))
(display-results "Tau numbers – first 100" 10 5
(take 100 (filter #(zero? (rem % (count (divisors %)))) (drop 1 (range)))))
(display-results "Divisor sums – first 100" 20 4
(take 100 (map #(reduce + (divisors %)) (drop 1 (range)))))
(display-results "Divisor products – first 100" 5 16
(take 100 (map #(reduce * (divisors %)) (drop 1 (range)))))
You may also check:How to resolve the algorithm Sort using a custom comparator step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the SequenceL programming language
You may also check:How to resolve the algorithm Lucas-Lehmer test step by step in the EchoLisp programming language
You may also check:How to resolve the algorithm Substring/Top and tail step by step in the Erlang programming language
You may also check:How to resolve the algorithm Fork step by step in the Factor programming language