No BSD License  

Hardy's Numbers

by

 

05 Jun 2003 (Updated )

Type "help hardy".

hardy.m
% ---------------------
% Hardy's Numbers
% ---------------------
%
% Prabhakar Subrahmanyam - prasub@yahoo.com
% June/05/2003
%
% ----------------------------------------------------------------------------
% Hardy who discovered the mathematical genius in Ramanujan was a great 
% mathematician himself. He once said there are only four numbers whose sum of 
% the cubes of their individual digits add up to the number itself. If 153
% is the number, (1^3)+(5^3)+(3^3)=153.
% This program will calculate those numbers
% ----------------------------------------------------------------------------


% Program begins - Prabhakar Subrahmanyam

clc % clear the screen before printing
clear all % clear all variables in memory

fprintf('\nHardy once said there are only four numbers whose sum of the');
fprintf('\ncubes of their individual digits add up to the number itself');
fprintf('\nIf 153 is the number, (1^3)+(5^3)+(3^3)=153\n\n');

n=3;
maxout=600;

for x=100:maxout

            first=fix(x/100); % gives the first digit
            temp_two=mod(x,100); % gives the last two digits
            second=fix(temp_two/10); % gives the second digit
            third=mod(x,10); % gives the third digit
            
            hardyx=(first^n);
            hardyy=(second^n);
            hardyz=(third^n);
            sumhardy=(hardyx+hardyy+hardyz);
            
                 if (x==hardyx+hardyy+hardyz) 
                       fprintf('%3d = %3d^3(%3d) +%3d^3(%3d) +%3d^3(%3d)\n',x,first,hardyx,second,hardyy,third,hardyz)
                 end  

end % for x



Contact us