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

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:

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



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.