Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
45
Task/Tau-function/Fennel/tau-function.fennel
Normal file
45
Task/Tau-function/Fennel/tau-function.fennel
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
(do ;;; find the count of the divisors of the first 100 positive integers
|
||||
|
||||
; returns the number of divisors of v
|
||||
(fn divisor-count [v]
|
||||
(var (total n) (values 1 v))
|
||||
; Deal with powers of 2 first
|
||||
(while (= 0 (% n 2))
|
||||
(set total (+ total 1))
|
||||
(set n (math.floor (/ n 2)))
|
||||
)
|
||||
; Odd prime factors up to the square root
|
||||
(var p 1)
|
||||
(while (do (set p (+ p 2))
|
||||
(<= (* p p) n)
|
||||
)
|
||||
(var count 1)
|
||||
(while (= 0 (% n p))
|
||||
(set count (+ count 1))
|
||||
(set n (math.floor (/ n p)))
|
||||
)
|
||||
(set total (* total count))
|
||||
)
|
||||
; If n > 1 then it's prime
|
||||
(when (> n 1)
|
||||
(set total (* total 2))
|
||||
)
|
||||
total
|
||||
)
|
||||
|
||||
(do
|
||||
(local limit 100)
|
||||
(io.write (.. "Count of divisors for the first " limit " positive integers:\n"))
|
||||
(for [n 1 limit]
|
||||
(io.write (string.format "%3d%s"
|
||||
(divisor-count n)
|
||||
(if (= 0 (% n 20))
|
||||
"\n"
|
||||
;else
|
||||
" "
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue