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 3357046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:35:12+00:00 2026-05-18T02:35:12+00:00

I need help on an algorithm. I have randomly generated numbers with 6 digits.

  • 0

I need help on an algorithm. I have randomly generated numbers with 6 digits. Like;

123654
109431

There are approximately 1 million of them saved in a file line by line. I have to filter them according to the rule I try to describe below.

Take a number, compare it to all others digit by digit. If a number comes up with a digit with a value of bigger by one to the compared number, then delete it. Let me show it by using numbers.

Our number is: 123456
Increase the first digit with 1, so the number becomes: 223456. Delete all the 223456s from the file.
Increase the second digit by 1, the number becomes: 133456. Delete all 133456s from the file, and so on…

I can do it just as I describe but I need it to be “FAST”.

So can anyone help me on this?

Thanks.

  • 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-05-18T02:35:13+00:00Added an answer on May 18, 2026 at 2:35 am

    This algorithm will keep a lot of numbers around in memory, but it will process the file one number at a time so you don’t actually need to read it all in at once. You only need to supply an IEnumerable<int> for it to operate on.

        public static IEnumerable<int> FilterInts(IEnumerable<int> ints)
        {
            var removed = new HashSet<int>();
    
            foreach (var i in ints)
            {
                var iStr = i.ToString("000000").ToCharArray();
    
                for (int j = 0; j < iStr.Length; j++)
                {
                    var c = iStr[j];
    
                    if (c == '9')
                        iStr[j] = '0';
                    else
                        iStr[j] = (char)(c + 1);
    
                    removed.Add(int.Parse(new string(iStr)));
    
                    iStr[j] = c;
                }
    
                if (!removed.Contains(i))
                    yield return i;
            }
        }
    

    You can use this method to create an IEnumerable<int> from the file:

        public static IEnumerable<int> ReadIntsFrom(string path)
        {
            using (var reader = File.OpenText(path))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                    yield return int.Parse(line);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help regarding algorithm for randomness. So Problem is. There are 50
I need help understanding some C++ operator overload statements. The class is declared like
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I have a regex call that I need help with. I haven't posted my
I have 2d-points (x,y) with float coordinates, when I draw them, I need to
I need help making an algorithm to detect that all the conditions for HAVE_ENOUGH_DATA
I need help selecting or creating a clustering algorithm according to certain criteria. Imagine
I have a coding/maths problem that I need help translating into C#. It's a
I need some help. I want to create one tournament. Let's say I have
I need help with an algorithm to allocate rooms to people. I need to

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.