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
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityconsecutive = Total[Abs[Differences[IntegerDigits@FromDigits@#]] - 1] &;
string = "123 321 567 765 124 568";
Pick[#, consecutive /@ #, 0]& @ StringSplit[string]
{"123", "321", "567", "765"}
Pick
andCases
could do the job? $\endgroup$