1
$\begingroup$

I have a text file containing a list of numbers. I want to print only the lines that contain a number, the digits of which are consecutive digits.

The input list:

123
321
567
765
124
568

The output should be:

123
321
567
765

$\endgroup$
1
  • $\begingroup$ Pick and Cases could do the job? $\endgroup$
    – Teabelly
    Oct 24 '18 at 17:33
1
$\begingroup$
consecutive = Total[Abs[Differences[IntegerDigits@FromDigits@#]] - 1] &;
string = "123 321 567 765 124 568";
Pick[#,  consecutive /@ #, 0]& @ StringSplit[string]

{"123", "321", "567", "765"}

$\endgroup$
1
  • $\begingroup$ Thank you @AccidentalFourierTransform. $\endgroup$
    – kglr
    Oct 24 '18 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.