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

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more