Skip to main content

Digital Sum

Digital Sum Digital Sum : The digital sum is the sum of the digits of a number taken iteratively till the result is less than 10. The problem statement is to get the number of integers less than 1 million where the digital sum is 1 and then, take the digital sum of this number which gives us the result. Note : Enable Javascript

Here is the recursive function in C#.

private void GetDigitalSum(double num, ref double num2) { //digital sum

double sum = 0;

for (int r = 0; r <= num.ToString().Length - 1; r++)
{
sum += double.Parse(num.ToString().Substring(r, 1));
}

if (sum.Equals(1))
{
num2 = -8;
return;
}
else
{
if (sum > 9)
{
GetDigitalSum(sum, ref num2);
}
else
{
num2 = sum;
}
}

}

//Here is calling subroutine

double no = 1;
double no2 = 0;
double sumr = 0;
double sumc = 0;

ArrayList ar = new ArrayList();

while (no < 1000000)
{
Application.DoEvents();
lblCounter.Text = no.ToString();

GetDigitalSum(no, ref no2);

if (no2.Equals(-8))
{
ar.Add(no);
sumr += double.Parse(no.ToString());
}

no += 1;

}

GetDigitalSum(ar.Count, ref no2);

MessageBox.Show(no2.ToString);

Click link to reveal answer

Comments

Popular posts from this blog

Chess blogging - Chessbase is back with a bang !

In view of my keen interest in UI for applications and websites, I feel it necessary to promote an investigation of the new play-chess interface on www.chessbase.com . * It is minimalistic * Allows you to play as Guest * Allows you to choose from different time-controls * Allows you to test your skills vis-a-vis opponents from across the globe Have a look at this interface, that is impressive from a UI developers point-of-view, and very conducive for a chess player to test his wits !  Whoa !  😇😇😇

Tomas ♟️Bot pgn

I beat this bot with an ELO of 1200 in Fischer 960 Chess ♟️  [Event "Vs. Computer"] [Site "Chess.com"] [Date "2025-01-28"] [White "petrushka_googol"] [Black "Tomas"] [Result "1-0"] [WhiteElo "400"] [BlackElo "1200"] [TimeControl "-"] [SetUp "1"] [FEN "qrkbbnnr/pppppppp/8/8/8/8/PPPPPPPP/QRKBBNNR w HBhb - 0 1"] [Variant "Chess960"] [Termination "petrushka_googol won by checkmate"] 1. e3 d6 2. Bf3 Bd7 3. Ng3 c5 4. Nh3 Bxh3 5. gxh3 Ba5 6. c3 h5 7. b4 Bc7 8. bxc5 dxc5 9. Nxh5 Nf6 10. Nxg7 Rh7 11. Nf5 e6 12. Ne7+ Kd8 13. O-O-O a6 14. c4 Kxe7 15. Rg1 Rd8 16. d3 Rh6 17. Bg4 Nxg4 18. hxg4 Qb8 19. g5 Rh7 20. Qf6+ Ke8 21. h4 Rd6 22. f4 Rb6 23. Rh1 Ng6 24. h5 Bd8 25. Qc3 Nf8 26. g6 Rb1+ 27. Kd2 Rxd1+ 28. Kxd1 fxg6 29. Rg1 g5 30. Bg3 Be7 31. fxg5 Qd8 32. Be5 Rxh5 33. Bf6 Bxf6 34. gxf6 Rh1 35. Rxh1 Qb6 36. Qc1 Kd8 37. Rh8 e5 38. Rxf8+ Kc7 39. Rf7+ Kc8 40. Re7 Qxf6 41. Re8...

B Trees🌲🌳🌴 databases and CHESS☺

Binary trees are a specific version of decision trees that have two nodes,one parent and two children, and this concept is used in database programming with relational databases like SQL server for creating in clustered and non clustered indexes. Alpha beta pruning together with B tree searches makeup the basis of chess programming. I have played a program that reached its thought horizon and then had a bizarre response inspite of  having an advantage of one pawn♟️