DEV Community

Judy
Judy

Posted on

3 1 1 1 1

Replace Duplicate Digits in Every 9-digit Number in a Text File with Non-duplicate Ones #eg52

Problem description & analysis

Below is text file txt.txt:

853617639 975336865

The text file contains multiple numeric strings. Each string is 9-digit, and strings are separated by white space. We are trying to process each numeric string and output information according to the following rule: If a digit appears repeatedly, replace it with one within 1-9 that has not been appeared before (find the replacement in natural order). Below is the desired result:

853617249 975316824

Solution

Write the following script p1.dfx in esProc:

Image description

Explanation:

A1   Read the text file as a string.

A2  Split numeric strings into a sequence using the white space, and each member string into a sequence of integers.

A3  Define cellset variable id as integer sequence of 1-9.

A4  Loop through A2, during which cellset variable pos is defined to represent the position where a duplicate integer appears and find an integer from 1 to 9 that has not appeared in order to replace the duplicate.

A5  Concatenate member sequences of a sequence into a string.

A6  Write A5’s result to result.txt.

SPL open source address

Download

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay