Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:11:35+00:00 2026-06-04T14:11:35+00:00

Possible Duplicate: Any chance to get unique records using Linq (C#)? using System; using

  • 0

Possible Duplicate:
Any chance to get unique records using Linq (C#)?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WaysOf100
{
class WaysOf100Test
{
    static void Main(string[] args)
    {
        WaysOf100 test= new WaysOf100();
        test.Go();
        test.EliminateDuplicates();
    }
}

class WaysOf100
{        
    List<string> results = new List<string>();             

    public void Go()
    {
        int num = 5, temp=0;//to store the intermediate difference
        for (int i = 1; i <num; i++)
        {
            temp = num - i;
            for (int j = 1; j <= temp; j++)
            {
                if (temp % j == 0)
                {   
                    //Console.Write(i + " ");
                    string text = "";                        
                    text = i.ToString();                        
                    for (int k = 1; k <= (temp / j); k++)
                    {
                        //Console.Write(j + " ");  
                        text += j.ToString();
                    }
                    char[] rev = text.ToCharArray();
                    Array.Reverse(rev);                       
                    if(!(results.Contains(rev.ToString())))
                        results.Add(text);                        

                }
            }                
        }
    }

    public void EliminateDuplicates()
    {            
        //To eliminate the duplicates   

        /*for (int i = 0; i < results.Count; i++)
        {

            for (int j = 0; j < results.Count; j++)
            {

                if (!(results[i].Equals(results[j])))
                {
                    char [] rev = results[j].ToCharArray();
                    Array.Reverse(rev);                        
                    if (results[i]==rev.ToString())
                        results.Remove(rev.ToString());
                }                                       
            }
        }*/

        foreach (var result in results)
        {
           Console.WriteLine(result);
        }
        Console.WriteLine("Total number of elements is :{0}",results.Count);
    }
}

}

The result so far is
11111
122
14
2111
23
311
32
41

This is what I want in short : the reverse of 41 is 14 and 14 already exists in the list so i don’t want to add 41. Similarly, the reverse of 32 is 23 which also exists and hence 32 should not be added. But this piece of could which I’ve written to achieve the functionality is not giving the desired results

if(!(results.Contains(rev.ToString())))
      results.Add(text);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:11:36+00:00Added an answer on June 4, 2026 at 2:11 pm

    The problem you are having is that rev.ToString()' returns "System.Char[]" and not the string value you wanted/expected. For your logic, try the following:

        public void EliminateDuplicates()
        {
            //Eliminate the duplicates    
    
            for (int i = 0; i < results.Count; i++)
            {
                for (int j = 0; j < results.Count; j++)
                {
                    if (!(results[i].Equals(results[j])))
                    {
                        char[] rev = results[j].ToCharArray();
                        char[] forward = results[i].ToCharArray();
                        Array.Reverse(rev);
                        bool bEqual = true;
                        for( int n = 0 ; n < results[j].Length && true == bEqual ; n++ )
                        {
                            if( rev[n] != forward[n] )
                            {
                                bEqual = false;
                            }
                        }
                        if( true == bEqual)
                            results.Remove(results[j] );
                    }
                }
            }
    
            foreach (var result in results)
            {
                Console.WriteLine(result);
            }
            Console.WriteLine("Total number of elements is : {0} ", results.Count);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is there any way to determine text direction from CultureInfo in asp.net?
Possible Duplicate: Any way to add HttpHandler programatically in .NET? Is there a way
Possible Duplicate: Is there any reason to use the 'auto' keyword in C /
Possible Duplicate: Overriding the power button in Android Is there any possible way I
Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Possible Duplicate: PHP: Script for generating Crossword game? Does anyone know any PHP-based simple
Possible Duplicate: C# member variable initialization; best practice? Is there any benefit to this:
Possible Duplicate: How are you using C++0x today? I'm working with a team on
Possible Duplicate: PHP global in functions Using something like this worries me: <? global
Possible Duplicate: Why can't decimal numbers be represented exactly in binary? i get very

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.