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

Discovery of India : India's most famous bachelors

Rahul Gandhi Ratan Tata Salman Khan A P J Abdul Kalam India is known for (or at least assumed to be famous for....)   - arranged marriages - lavish weddings   In this context the ideal of remaining a bachelor (unsullied, so to speak) remains a questionable paradigm.   However, there are some truly exceptional Indians who have never taken the plunge.   Here is a brief listing of the same :   1. Rahul Gandhi - Scion of the Gandhi family, grandson of Indira Gandhi (ex-PM), son of Sonia Gandhi (de-facto head of the Congress Party). He has decided to go it alone, possibly putting an end to the dynasty politics associated with his family.   2. Ratan Tata : Scion of the Tata family, which is a multi-billion dollar conglomerate holder, and Chairman of the Tata group. In spite of company politics, affecting recent fortunes of the group, he remains a mystical and enigmatic figure.   3. Salman Khan : Son of Salim Khan, a Hindi mo