How to resolve the algorithm Next highest int from digits step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Next highest int from digits step by step in the Quackery 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:
Step by Step solution about How to resolve the algorithm Next highest int from digits step by step in the Quackery programming language
Source code in the quackery programming language
[ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] is ->digits ( n --> [ )
[ 0 swap
witheach
[ swap 10 * + ] ] is digits-> ( [ --> n )
[ dup ->digits
nextperm
digits->
tuck < not if
[ drop 0 ] ] is task ( n- -> n )
' [ 0 9 12 21 12453 738440 45072010
95322020 9589776899767587796600 ]
witheach [ task echo sp ]
You may also check:How to resolve the algorithm Find largest left truncatable prime in a given base step by step in the Perl programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Rust programming language
You may also check:How to resolve the algorithm UTF-8 encode and decode step by step in the Processing programming language
You may also check:How to resolve the algorithm System time step by step in the zkl programming language
You may also check:How to resolve the algorithm Number names step by step in the Rust programming language