All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Algorithms
Year Yearn 5 (Posted on 2023-06-28) Difficulty: 3 of 5
Define sod(x) as the sum of the digits of x.
For example, sod(1245984)= 1+2+4+5+9+8+4= 33.

Devise an algorithm to determine the value of:
sod(20232023).

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution (spoiler) | Comment 1 of 4
yp=char(sym(2023)^2023);
disp(length(yp))
disp(sod(yp))

finds that the 6689 digits of the power add up to 30,112:

>> yearYearn5
        6689
       30112
>> 

where the sod function is

function sd = sod(n0)
  sd=0;
  n1=char(string(n0));
  for i=1:length(n1)
   sd=sd+str2double(n1(i));
  end
end

which unnecessarily converts the character string to a unitary string and back again as the sod function is written so that it would work even on a numeric, so in fact the char function in the outer function was not really necessary except to find the length of the number, which was not really asked for in the puzzle.

So

yp=sym(2023)^2023;
disp(sod(yp))

works just as well as the above in finding only

>> yearYearn5
       30112
>> 

  Posted by Charlie on 2023-06-28 08:42:31
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information