Skip to main content

Near symmetric numbers

--> Near symmetric numbers Near symmetric numbers : Those numbers which when reversed and added to the original do not equal each other even after 25 iterations :

Here is the recursive function....

private void GeneratePalindromeTotals(double num1, double num2, ref int nc, ref ArrayList ar)
{

ar = new ArrayList();

string rvnum1 = String.Empty;
string rvnum2 = String.Empty;

double rnum = 0;
string snum2 = String.Empty;

string snum1 = num1.ToString();

int lnum1 = snum1.Length;

for (int u = lnum1 - 1; u >= 0; u--)
{
snum2 += snum1.Substring(u, 1);
}

num2 = double.Parse(snum2);

rnum = num1 + num2;

rvnum1 += rnum.ToString();

for (int rv = rnum.ToString().Length - 1; rv >= 0; rv--)
{
rvnum2 += rvnum1.ToString().Substring(rv, 1).ToString();
}

if (!(rvnum1.Equals(rvnum2)))
{
File.AppendAllText(@"C:\WriteLines.txt", "No is : " + num1.ToString() + " , Diff : rvnum1 = " + rvnum1 + " ," + "rvnum2 = " + rvnum2 + " ,nc = " + nc.ToString() + Environment.NewLine);

nc += 1;
if (nc.Equals(26)) return;

GeneratePalindromeTotals(double.Parse(rvnum1), double.Parse(rvnum2), ref nc, ref ar);

rvnum1 = String.Empty;
rvnum2 = String.Empty;
snum2 = String.Empty;

}
else
{
File.AppendAllText(@"C:\WriteLines.txt", "No is : " + num1.ToString() + " , Same : rvnum1 = " + rvnum1 + " ," + "rvnum2 = " + rvnum2 + " ,nc = " + nc.ToString() + Environment.NewLine);
nc = 0;
return;
}
}

//Calling routine

int a_nc = 0;
ArrayList a_ar = new ArrayList();

for (double a_no1 = 1; a_no1 < 200; a_no1++)
{
Application.DoEvents();
lblCounter.Text = a_no1.ToString();

GeneratePalindromeTotals(a_no1, a_no1, ref a_nc, ref a_ar);
if (a_nc.Equals(26)) { MessageBox.Show(a_no1.ToString()); break; }
}

Dry run of program as it iterates...

Answer : 196

Comments

Popular posts from this blog

#The Witch meets her nemesis

Sample pgn file for win over Witch bot [Event "Vs. Computer"] [Site "Chess.com"] [Date "2023-09-17"] [White "Witch"] [Black "petrushka_googol"] [Result "0-1"] [TimeControl "-"] [SetUp "1"] [FEN "rnbqknrb/pppppppp/8/8/8/8/PPPPPPPP/RNBQKNRB w GAga - 0 1"] [Variant "Chess960"] [Termination "petrushka_googol won by checkmate"] 1. d4 d5 2. Nc3 e6 3. Qd3 Qf6 4. Nb5 Qe7 5. Qc3 c6 6. Na3 Na6 7. Bd2 Bd7 8. Qe3 g6 9. O-O-O f5 10. g4 O-O-O 11. Kb1 Kb8 12. Qd3 e5 13. g5 e4 14. Qc3 c5 15. Bf Ka8 16. e3 cxd4 17. exd4 Bc6 18. Qe3 Ne6 19. Be5 Bxe5 20. dxe5 Nb4 21. c3 Nd3 22. Rxd3 exd3 23. Qxd3 Nc5 24. Qd4 Na4 25. Nc2 b5 26. f4 Qf7 27. Nb4 Bb7 28. b3 Nb6 29. Ne3 a5 30. Qxb6 axb4 31. cxb4 d4 32. Nc2 Bxh1 33. Rxh1 d3 34. Nd4 d2 35. e6 Qe7 36. Qa6+ Qa7 37. Qc6+ Qb7 38. Qxb7+ Kxb7 39. Nxb5 Kb6 40. Nc3 Rge8 41. Kc2 Rxe6 42. Rb1 Re1 43. Rd1 Rxd1 44. Kxd1 Rd3 45. Na4+ Kb5 46. Nc5 Rh3 47. Kxd2 Rxh2+ 48

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 !  😇😇😇

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♟️