How to resolve the algorithm Next highest int from digits step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Next highest int from digits step by step in the J programming language

Table of Contents

Problem Statement

Given a zero or positive integer, the task is to generate the next largest integer using only the given digits*1.

The above could prove slow and memory hungry for numbers with large numbers of digits, but should be easy to reason about its correctness.

E.g.: This second algorithm is faster and more memory efficient, but implementations may be harder to test. One method of testing, (as used in developing the task),   is to compare results from both algorithms for random numbers generated from a range that the first algorithm can handle.

Calculate the next highest int from the digits of the following numbers:

Let's start with the solution: