Add tags

Add tags to the following comment
整数部分は配列(リスト)のインデックスで、小数部分は二分探索的なアプローチで求めています。
三乗根がピッタリ整数の場合は、整数で答えを出すようにしたので、ちょっと長くなりました。

実行例:
arc> (search-cube-root 10.0)
2.1544346900318487
arc> (expt (search-cube-root 10.0) 3)
9.999999999999513
arc> (search-cube-root 100.0)
4.641588833612786
arc> (expt (search-cube-root 100.0) 3)
100.00000000000048
arc> (search-cube-root 125.0)
5
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
(= cube-list (map [expt _ 3] (range 1 10)))
(= acc 0.000000000001)

(def search-real (cr of rn)
  (let gosa (- rn (expt cr 3))
    (if (< (abs gosa) acc)
        cr
        (if (< 0 gosa)
            (search-real (+ cr of) (/ of 2) rn)
            (search-real (- cr of) (/ of 2) rn)))))

(def search-cube-root (rn)
  (if (is (type rn) 'int)
      (let i (trunc rn)
        (if (mem i cube-list)
            (+ (pos i cube-list) 1)
            (search-real (+ (pos i (sort < (cons i cube-list))) 0.5) 0.25 rn)))
      (search-real (+ (pos rn (sort < (cons rn cube-list))) 0.5) 0.25 rn)))

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...