ラマヌジャン数
ラマヌジャンは療養所に入っており、見舞いに来たハーディーは次のようなことを言った。
「乗ってきたタクシーのナンバーが1729だった。特に特徴のない、つまらない数字だったよ」
これを聞いたラマヌジャンは、すぐさま次のように言った。
「そんなことはありません。とても興味深い数字です。それは2通りの2つの立方数の和で表せる最小の数です」
30分プログラム、その143。ラマヌジャンの言った数字を探してみよう。
使い方
gosh> (make-nums 100) (1 12 9 10) (1 12 10 9) (9 10 1 12) (9 10 12 1) (10 9 1 12) (10 9 12 1) (12 1 9 10) (12 1 10 9)
ソースコード
#! /opt/local/bin/gosh ;; -*- mode:scheme; coding:utf-8 -*- ;; ;; ramanujan.scm - ;; ;; Copyright(C) 2007 by mzp ;; Author: MIZUNO Hiroki <hiroki1124@gmail.com> ;; http://mzp.sakura.ne.jp/ ;; ;; Timestamp: 2007/09/26 22:38:01 ;; ;; This program is free software; you can redistribute it and/or ;; modify it under the same terms as Scheme itself. ;; (use srfi-1) (use util.combinations) (define (ramanujan? a b c d) (define (f n) (* n n n)) (= (+ (f a) (f b)) (+ (f c) (f d)))) (define nums (iota 10)) (define (make-nums n) (combinations-for-each (lambda(xs) (permutations-for-each (lambda(ys) (if (apply ramanujan? ys)(print ys))) xs)) (iota n 1) 4))