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

  • Home
  • SEARCH
  • 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 8708369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:07:21+00:00 2026-06-13T04:07:21+00:00

I have a plaintext file that has only numerical digits in it (no spaces,

  • 0

I have a plaintext file that has only numerical digits in it (no spaces, commas, newlines, etc.) which contains n digits which range from 0 to 255. I want to take it in and store these values in an array.

Example


Let’s say we have this sequence in the file:

581060100962552569

I want to take it in like this, where in.read is the file input stream, tempArray is a local array of at most 3 variables that is wiped every time something is stored in endArray, which is where I want the final values to go:

in.read     tempArray     endArray
5           [5][ ][ ]     [] //It reads in "5", sees single-digit number X guarantees that "5X" is less than or equal to 255, and continues
8           [5][8][ ]     [58] //It reads in "8", realizes that there's no number X that could make "58X" smaller than or equal to "255", so it stores "58" in endArray
1           [1][ ][ ]     [58] //It wipes tempArray and reads the next value into it, repeating the logic of the first step
0           [1][0][ ]     [58] //It realizes that all single-digit numbers X guarantee that "10X" is less than or equal to "255", so it continues
6           [1][0][6]     [58][106] //It reads "6" and adds "106" to the endArray
0           [0][ ][ ]     [58][106] //It wipes tempArray and stores the next value in it
1           [0][1][ ]     [58][106]
0           [0][1][0]     [58][106][10] //Even though all single-digit numbers X guarantee that "010X" is less than or equal to "255", tempArray is full, so it stores its contents in endArray as "10".
0           [0][ ][ ]     [58][106][10]
9           [0][9][ ]     [58][106][10]
6           [0][9][6]     [58][106][10][96] //Not only can "96" not have another number appended to it, but tempArray is full
2           [2][ ][ ]     [58][106][10][96]
5           [2][5][ ]     [58][106][10][96] //There are numbers that can be appended to "25" to make a number less than or equal to "255", so continue
5           [2][5][5]     [58][106][10][96][255] //"5" can be appended to "25" and still be less than or equal to "255", so it stores it in tempArray, finds tempArray is full, so it stores tempArray's values in endArray as "255"
2           [2][ ][ ]     [58][106][10][96][255][37]
5           [2][5][ ]     [58][106][10][96][255][37] //There are numbers that can be appended to "25" to make a number less than or equal to "255", so continue
6           [6][ ][ ]     [58][106][10][96][255][37][25] //It sees that adding "6" to "25" would make a number that's larger than 255, so it stores "25" in the endArray and remembers "6" in the tempArray
9           [6][9][ ]     [58][106][10][96][255][37][25][69] //It sees that there is no number X such that "69X" is less than "255", so it stores "69" in endArray

Does anyone know how I can accomplish this behavior? Please try to keep your answers in pseudocode, so it can be translated to many programming langauges

  • 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-13T04:07:22+00:00Added an answer on June 13, 2026 at 4:07 am

    I would not use the temp array for holding the intermediate numbers – for the CPU numbers are stored in binary format and you are reading decimal numbers.

    Something like this could solve your problem:

    array = []
    accumulator = 0
    count = 0
    while not EOF:
        n = readDigit()
        if accumulator*10 + n > 256 or count == 2:
             array.push(accumulator)
             accumulator = n
             count = 0
        else:
             accumulator = accumulator*10 + n
             count = count + 1
    

    The results are appended to the array called array.

    Edit: Thanks to DeanOC for noticing the missing counter. But DeanOC’s solution initializes the counter for the first iteration to 0 instead of 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have plain text file ( .txt ) which has some expressions and I
I have about 40000 records in that table that contains plain text and within
I'm trying to load a file in a VBA macro that has been copied
I have a plain text file that I need to read in using C#,
Localizable strings file which are used for Apple/iPhone apps localization have the following format:
I have an existing data format that has portions of it encrypted in what
I have a file with two columns, one has the content type of HTTP
I have a function in my Django app that has a dictionary containing several
In my application I have a config.xml file which is being parsed,. In this
I have a matrix that has 20 rows and 51 columns. I would like

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.