UP | HOME

哈代-拉馬努金數

最近又看到哈代跟拉馬努金的 1729,所以就寫了一下程式去找能夠被表示成兩種以上立方和的數

1729
4104
13832
20683
32832
39312
40033
46683
64232
65728
110656
110808
134379
149389
165464
171288
195841
216027
216125
262656
314496
320264
327763
373464
402597
439101
443889
513000
513856
515375
525824
558441
593047

順道一提,Matt Parker 說他有試著去找那台計程車(爆雷:沒有找到)

1. 程式部分

(define cache (make-hash))

(for ([n (in-combinations (range 1 400) 2)])
  (define a (first n))
  (define b (second n))
  (define v (+ (expt a 3) (expt b 3)))
  (if (hash-has-key? cache v)
      (hash-update! cache v (λ (v) (cons (cons a b) v)))
      (hash-set! cache v (list (cons a b)))))

((compose (λ (keys) (map (λ (k)
			   k)
			 keys))
	  (λ (keys) (sort keys <=))
	  (λ (cache)
	    (for/list ([(k v) (in-hash cache)]
		       #:when ((length v) . >= . 2))
	      k)))
 cache)

Date: 2022-11-16 Wed 00:00

Author: Lîm Tsú-thuàn